如何在关联模型中查找()/ where()
我正在玩风帆模型协会,我很好奇,如果有可能在相关领域作出查询的基础。
例:
User.js attributes:{ classes: { collection: 'Class', via: 'students' } } Class.js attributes: { type: ... students: { collection: 'User', via: 'classes'} }
有没有办法根据类的类来检索一个Student类的特定类,因为现在当我使用.populate()
时,所有的东西都被返回。 (也许类似于下面的逻辑)
User .findOne({name: 'StudentA'}) .populate('classes') .where({'classes.type':['type1', 'type2']}) .then(....)
谢谢
您可以像这样添加一个where
子句到您的populate
:
User .findOne({name: 'StudentA'}) .populate('classes', {where: {type: ['type1', 'type2']}}) .exec(...)
除了在where
,你还可以使用skip
, limit
和sort
在第二个参数来populate
。
请记住,这仍然是(在此张贴)在testing版,所以如果你发现任何问题似乎不能正常工作,请张贴到水线GitHub问题论坛 。