node.js - How to do find() / where() in associated models -
i'm playing model associations in sails , i'm curious if it's possible make query base on associated field.
example:
user.js attributes:{ classes: { collection: 'class', via: 'students' } } class.js attributes: { type: ... students: { collection: 'user', via: 'classes'} } is there way retrieve specific classes of student base on type of class because right being returned when use .populate(). (maybe similar logic below)
user .findone({name: 'studenta'}) .populate('classes') .where({'classes.type':['type1', 'type2']}) .then(....) thanks
you can add where clause populate so:
user .findone({name: 'studenta'}) .populate('classes', {where: {type: ['type1', 'type2']}}) .exec(...) in addition where, can use skip, limit , sort in second argument populate.
keep in mind still (as of posting) in beta, if find issues seems not working correctly, please post them waterline github issues forum.
Comments
Post a Comment