Javascript 执行包含以下内容时字段列表中的未知列(&U);使用col方法时有许多关联
希望我能尽可能最好地解释这个问题 我有三个模型Javascript 执行包含以下内容时字段列表中的未知列(&U);使用col方法时有许多关联,javascript,node.js,express,sequelize.js,Javascript,Node.js,Express,Sequelize.js,希望我能尽可能最好地解释这个问题 我有三个模型 财产 销售类型 不动产 Property有一个SaleType,但可以有多个PropertyUnit 这里是协会 财产 销售类型 财产单位 在我的findAll中,查询属性方法。我想回来 属性的id text\u键属性在SaleType中作为单个属性与SaleType别名一起使用 PropertyUnit数组,每个属性都带有street属性 我的问题如下: await Property.findAll({ attributes: [
- 财产
- 销售类型
- 不动产
Property
有一个SaleType
,但可以有多个PropertyUnit
这里是协会
财产
销售类型
财产单位
在我的findAll
中,查询属性
方法。我想回来
属性的
id
属性在text\u键
中作为单个属性与SaleType
别名一起使用SaleType
数组,每个属性都带有PropertyUnit
属性street
await Property.findAll({
attributes: [
'id',
[sequelize.col('saleTypeRef.text_key'), 'saleType'],
],
include: [
{
model: Models.SaleType,
as: 'saleTypeRef',
attributes: []
},
{
model: Models.PropertyUnit,
as: 'propertyUnit',
attributes: [ 'street' ],
},
],
});
这就是我得到以下错误的地方
"SequelizeDatabaseError: Unknown column 'saleTypeRef.text_key' in 'field list'
使用以下查询
SELECT
`Property`.*,
`propertyUnit`.`id` AS `propertyUnit.id`,
`propertyUnit`.`street` AS `propertyUnit.street`
FROM
(SELECT
`Property`.`id`,
`saleTypeRef`.`text_key` AS `saleType`,
`Property`.`sale_type_id`
FROM
`property_demo`.`property` AS `Property`
) AS `Property`
LEFT OUTER JOIN
`property_demo`.`sale_type` AS `saleTypeRef` ON `Property`.`sale_type_id` = `saleTypeRef`.`id`
LEFT OUTER JOIN
`property_demo`.`property_unit` AS `propertyUnit` ON `Property`.`id` = `propertyUnit`.`property_id`;
因此,saleTypeRef.text_键
不能被引用,但如果要在首字母中添加它,请选择
,它会起作用
移除
[sequelize.col('saleTypeRef.text_key'), 'saleType'],
不会返回任何错误,但也不会返回所需的属性。
或者删除属性yunit
模型的include也可以,但同样不会返回我需要的属性
那么,有没有办法达到我上面列出的结果呢
任何帮助都将不胜感激
await Property.findAll({
attributes: [
'id',
[sequelize.col('saleTypeRef.text_key'), 'saleType'],
],
include: [
{
model: Models.SaleType,
as: 'saleTypeRef',
attributes: []
},
{
model: Models.PropertyUnit,
as: 'propertyUnit',
attributes: [ 'street' ],
},
],
});
"SequelizeDatabaseError: Unknown column 'saleTypeRef.text_key' in 'field list'
SELECT
`Property`.*,
`propertyUnit`.`id` AS `propertyUnit.id`,
`propertyUnit`.`street` AS `propertyUnit.street`
FROM
(SELECT
`Property`.`id`,
`saleTypeRef`.`text_key` AS `saleType`,
`Property`.`sale_type_id`
FROM
`property_demo`.`property` AS `Property`
) AS `Property`
LEFT OUTER JOIN
`property_demo`.`sale_type` AS `saleTypeRef` ON `Property`.`sale_type_id` = `saleTypeRef`.`id`
LEFT OUTER JOIN
`property_demo`.`property_unit` AS `propertyUnit` ON `Property`.`id` = `propertyUnit`.`property_id`;
[sequelize.col('saleTypeRef.text_key'), 'saleType'],