I need to select users with dogs (pets with type
equal \'dog\')
var User = Waterline.Collection.extend({
identity: \'user\',
attributes: {
What you are looking for hasn't been implemented in waterline (Sails ORM) yet, check issue #266 for more details.
User.find().populate('pets', {type: 'dog'}).exec(err, users) ...
This will return all users (User.find()
) and only populate pets of type dog (populate('pets', {type: 'dog'})
). So you'll have users without dogs in your results.
User.find().where({'pets.type': 'dog'}).populate('pets').exec(err, users) ...
Waterline does not support dot (.) notation. Sails-mongo does have some support for it due to MongoDB support.
Finally, if you are using one of the SQL adapters you may work around this by doing a raw sql query using .query()
(docs).
If you don't need to query users and just need the query for dogs. You could just as easily reverse the query.
Pet.find({type: 'dog'}).populate('users').exec(err, petsWithUsers)
Did you try this?
User.find().populate('pets', {
where: {
type: 'dog'
}
}).exec(err, users)...