Monday 22 April 2019

Sequelize, is it possible to get all of a Model's associated records using the model instance?

If I've setup an association User.hasMany( models.Messages )And when I get a Model instance targetUser from using models.User.findOne({ where:{id: a_user_id} }).then(targetUser) =>Can I just simply call a method like targetUser.getAllMyMessages() I don't want to have to search all the messages where the userId equals ... that seems inefficient (because what if there's over a million messages).

Submitted April 22, 2019 at 06:46AM by horrofan

No comments:

Post a Comment