Reputation: 353
Newbie here, is there a way to add criteria when using .populate in sails js. Or is it even possible to do so?
Ex.
Model.find().populate('toPopulate', {"toPopulate.toFind" : {$in: [1,2,3,4]}}).exec(console.log);
Please shed some light
Thanks
Upvotes: 1
Views: 395
Reputation: 353
@mdunisch's answer is almost correct, just needed to include @sgress454's fix. So here is the working example on how to add filters in populate.
Model.find().populate('toPopulate',
{where: {id: [1,2,3,4]}}).exec(console.log);
OR
you can also do it without where
Model.find().populate('toPopulate', {id: [1,2,3,4]}).exec(console.log);
Upvotes: 1
Reputation: 3697
Try:
Model.find().populate('toPopulate',
where: {
id: [1,2,3,4]
}
).exec(console.log);
Upvotes: 1