sequelize freezeTableName but still plural table name in sql query
<p>I'm using <strong>express+ionic+mysql+sequelize</strong> to develop an app, now I got a error in the sequelize.<br>
I got three tables which are   </p>

<ul>
<li><p>xx_product  </p></li>
<li><p>xx_product_specification_value</p></li>
<li><p>xx_specification_value</p></li>
</ul>

<p>the relations between them as below:</p>

<pre><code>xx_product                     hasMany     xx_product_specification_value
xx_specification_value         hasMany     xx_product_specification_value
xx_product_specification_value belongsTo   xx_product
xx_product_specification_value belongsTo   xx_specification_value
</code></pre>

<p>here is the code:</p>

<p>models/products.js</p>

<pre><code>module.exports = function(sequelize, DataTypes){
  return xx_product = sequelize.define('xx_product', {
    price: {
      type: DataTypes.DECIMAL
    },
    full_name: {
      type: DataTypes.STRING
    },
    name: {
      type: DataTypes.STRING
    },
    image: {
      type: DataTypes.STRING
    },
    introduction: {
      type: DataTypes.TEXT
    },
    xxSupplierId: {
      type: DataTypes.BIGINT,
      field: 'supplier'
    },
    xxBrandId: {
      type: DataTypes.BIGINT,
      field: 'brand'
    }
  },{
      freezeTableName: true,
      tableName: 'xx_product',
      timestamps: false,
      classMethods: {
        associate: function(models) {
          xx_product.belongsTo(models.xx_supplier, {
            foreignKey: 'supplier'
          })
          xx_product.belongsTo(models.xx_brand, {
            foreignKey: 'brand'
         })
          xx_product.hasMany(models.xx_product_specification_value)
        }
      }
    })
  }
</code></pre>

<p>models/product_specification_value.js</p>

<pre><code>module.exports = function(sequelize, DataTypes){
  return xx_product_specification_value = sequelize.define('xx_product_specification_value', {
    xxProductId: {
      type: DataTypes.BIGINT,
      field: 'products'
    },
    xxSpecificationValueId: {
      type: DataTypes.BIGINT,
      field: 'specification_values'
    }
  },{
    freezeTableName: true,
    tableName: 'xx_product_specification_value',
    timestamps: false,
    classMethods: {
      associate: function(models) {
        xx_product_specification_value.belongsTo(models.xx_product, {
          foreignKey: 'products'
        })
            xx_product_specification_value.belongsTo(models.xx_specification_value, {
      foreignKey: 'specification_values',
    })
    }
    }
  })
}
</code></pre>

<p>models/specification_value.js</p>

<pre><code>module.exports = function(sequelize, DataTypes){
  return xx_specification_value = sequelize.define('xx_specification_value', {
    name: {
      type: DataTypes.STRING
    },
    image: {
      type: DataTypes.STRING
    },
    xxSpecificationId: {
      type: DataTypes.BIGINT,
      field: 'specification'
    }
  },{
    freezeTableName: true,
    tableName: 'xx_specification_value',
    timestamps: false,
    classMethods: {
      associate: function(models) {
        xx_specification_value.hasMany(models.xx_product_specification_value)
        xx_specification_value.belongsTo(models.xx_specification, {
          foreignKey: 'specification'
        })
      }
    }
  })
}
</code></pre>

<p>routes/product.js</p>

<pre><code>var models = require('../models')

exports.show = function(req, res){
  var id = req.params.id
  models.xx_product.findOne({
    where: {
      id: id,
    },
    include: [
      {
        model: models.xx_product_specification_value,
        include: [
           {
             model: models.xx_specification_value,
             include: [
               {
                 model: models.xx_specification
               }
             ]
           }
         ]
      }
    ]
  })
  .then(function(product){
    res.json(product)
  })
}
</code></pre>

<p>when I invoke show in routes/products.js to query, I got error in console as below:</p>

<pre><code>Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR:  
Unknown column 'xx_product_specification_values.id' in 'field list' 
</code></pre>

<p>the sql query in console as below:</p>

<pre><code>Executing (default): SELECT `xx_product`.`id`, `xx_product`.`price`, 
`xx_product`.`full_name`, `xx_product`.`name`, `xx_product`.`image`,    
`xx_product`.`introduction`, `xx_product`.`supplier` AS 
`xxSupplierId`, `xx_product`.`brand` AS `xxBrandId`,   
`xx_product`.`supplier`, `xx_product`.`brand`, 
`xx_product_specification_values`.`id` AS 
`xx_product_specification_values.id`, 
`xx_product_specification_values`.`products` AS 
`xx_product_specification_values.xxProductId`,   
`xx_product_specification_values`.`specification_values` AS 
`xx_product_specification_values.xxSpecificationValueId`, 
`xx_product_specification_values`.`products` AS 
`xx_product_specification_values.products`, 
`xx_product_specification_values`.`specification_values` AS 
`xx_product_specification_values.specification_values` FROM 
`xx_product` AS `xx_product` LEFT OUTER JOIN 
`xx_product_specification_value` AS `xx_product_specification_values` 
ON `xx_product`.`id` = `xx_product_specification_values`.`products` 
WHERE `xx_product`.`id` = '1742';
</code></pre>

<p>my question is why it query as <strong>xx_product_specification_values</strong> not as <strong>xx_product_specification_value</strong>, why it's plural? I have set <strong>freeszeTableName = true</strong> and set <strong>tableName = xx_product_specification_value</strong></p>