简体   繁体   中英

Having into Include model using Sequelize.js

I have a problem whith join using 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 :

this.users.findAll({
    include: [
        {
            model: History,
            separate : true ,
            order : [['date','desc']] ,
            limit : 1
        }
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM