我正在使用sails 中的模型关联,我很好奇是否可以根据关联字段进行查询。
例子:
User.js
attributes:{
classes: { collection: 'Class', via: 'students' }
}
Class.js
attributes: {
type: ...
students: { collection: 'User', via: 'classes'}
}
有没有办法根据类的类型检索学生的特定类,因为现在我使用.populate()
. (可能与下面的逻辑类似)
User
.findOne({name: 'StudentA'})
.populate('classes')
.where({'classes.type':['type1', 'type2']})
.then(....)
谢谢