Suppose that I have the following models in Sails.js v0.10:
Person.js
module.exports = {
attributes: {
name: 'string',
books: {
collection: 'book',
via: 'person'
}
}
};
Book.js
module.exports = {
attributes: {
name: 'string',
person: {
model: 'person'
}
}
};
I want a query to return an array of people that have a certain associated book. I would like to do something like the following query, but i don't know how:
Person.find()
.populate('books')
.where({ books.name: 'Game of Thrones'})
.exec(function(err, person) {
if (err) return res.send(err, 500);
res.json(person);
});
Any ideas if this is possible to do using a simple query?