Join 使用include in sequelize(node.js express)中的models.sequelize.col()时出现不明确错误
马里亚布Join 使用include in sequelize(node.js express)中的models.sequelize.col()时出现不明确错误,join,include,sequelize.js,mariadb,Join,Include,Sequelize.js,Mariadb,马里亚布 show tables; Board Comment 我的代码 models.Board.findAll({ attributes: [ '_no', 'title', 'content', 'createdAt' ], include: [ { model: models.Comment, tableAlias: 'Comment', attributes: [ [models.sequelize.fn('count', models.s
show tables;
Board
Comment
我的代码
models.Board.findAll({
attributes: [
'_no', 'title', 'content', 'createdAt'
],
include: [
{
model: models.Comment,
tableAlias: 'Comment',
attributes: [
[models.sequelize.fn('count', models.sequelize.col('_no')), 'comment']
]
}
],
group: ['_no', 'title', 'content', 'createdAt'],
order: [
['createdAt', 'DESC']
],
raw: true
}).then(function(boards)
{
res.send(JSON.stringify(boards));
});
为什么会发生错误
Unhandled rejection SequelizeDatabaseError: ER_NON_UNIQ_ERROR: Column '_no' in field list is ambiguous
models.sequelize.col('u no')->models.sequelize.col('models.Comment.'u no'))
也有错误
不想使用注释表中的models.sequelize.col('''no')
谢谢。显然董事会和评论都有一个
\u no
栏?在这种情况下,您需要指定要计算哪一个,fx:models.sequelize.col('board.\u no'))
(确保表名与查询其余部分中表的复数和大写匹配)I。问题是表对象的命名。谢谢。但是如果你不知道从哪里会包括在内,在桌子上怎么做呢?有什么线索吗?@Jan,你能不能给我一个提示?