Couldn't find what I wanted in the documentation, so I'm just going to leave this here and hope for some help!
I have a specific query that I need to run on my user Model with a lot of includes and those includes all have where statements inside of them... So, I'd like to unclutter my controller and put this logic
User.findById(userId, {include: [{
model: Model1,
where: { aCondition: false}
},{
model: Model2,
where: { aCondition: false}
},{
model: Model3,
where: { aCondition: false}
},{
model: Model4,
where: { aCondition: false}
},{
model: Model5,
where: { aCondition: false}
}]}).then()
into the Model itself so I'd just be able to call
User.findByIdWithIncludes(userId).then()
inside of my controller.
Does this functionality exist and I'm just missing it?
Any help/advice would be greatly appreciated.
Thanks!
This kind of select can be done with the use of "Scopes", http://sequelize.readthedocs.org/en/latest/docs/scopes/
By defining your models like that:
It will be used with every find(). You can define multiple scopes.