Sequelize - Where is the offer with associations
In sequelize I have board and user settings, with many associations as follows
User.hasMany(Board, {through: BoardUsers});
Board.hasMany(User, {through:BoardUsers});
Anyway, using the where clause, I can find users belonging to one of the board lists. For example, lets say I have 3 boards, and I would like to find the first 20 users (using the default sort order) that belong to the same board 1 or 3. Is there a way to do this without doing separate finds for each board, then manually combining the results.
I would like to do something like:
User.findAll({where:{board: [1,3]}});
but I cannot find a way to do this.
As far as I can tell, the equivalent SQL would be something like this:
SELECT * FROM `users` WHERE id IN (SELECT userID FROM boardusers WHERE boardId IN (1,3))
But I would be happy to do it through the ORM.
+3
source to share
2 answers