Elena Alexeenko
Elena Alexeenko

Reputation: 120

Sequelize : Using 'where' in 'include' in findByPk

In Sequelize I´m using findByPk but I also need to pass another condition

return dependencies.db.models.user.findByPk(userId, {
        include: [
            {
                model: dependencies.db.models.userGroup,
                required: false,
                where: {
                    Time: null,
                },

I know that 'options.where' is not supported for findByPk , however it is being used inside of a include. I couldn't find verification in the sequelize documentation that what I am doing is correct.

Upvotes: 3

Views: 10697

Answers (1)

Wang Liang
Wang Liang

Reputation: 4444

return dependencies.db.models.user.findByPk(userId, {
        include: [
            {
                model: dependencies.db.models.userGroup,
                required: false,
                where: {
                    Time: { [op.eq]:null }
                },

Upvotes: 7

Related Questions