[英]Having into Include model using Sequelize.js
I have a problem whith join using sequelize.js.我在使用 sequelize.js 加入时遇到问题。 I need a last History date for all users.我需要所有用户的最后一个历史日期。 I'm try this, but something is wrong:我正在尝试这个,但有些不对劲:
this.users.findAll({
include: [
{
model: History,
attributes: [
'value',
'date'
],
having: { date: [sequelize.fn('MAX', sequelize.col('date')), 'max_date']}
}
]
}
This does not work, I wonder if you have any idea how to return this result.这不起作用,我想知道您是否知道如何返回此结果。
Thanks谢谢
I think you can do this by order by
and limit
, Here you go :我认为你可以通过order by
和limit
来做到这一点,你去吧:
this.users.findAll({
include: [
{
model: History,
separate : true ,
order : [['date','desc']] ,
limit : 1
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.