2

セイルでモデルの関連付けを行っていますが、関連付けられたフィールドに基づいてクエリを作成できるかどうか知りたいです。

例:

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(....)

ありがとう

4

1 に答える 1

0

次のようにwhere句を追加できます。populate

User
 .findOne({name: 'StudentA'})
 .populate('classes', {where: {type: ['type1', 'type2']}})
 .exec(...)

に加えて、2 番目の引数でとをwhere使用することもできます。skiplimitsortpopulate

これはまだ (この投稿の時点で) ベータ版であるため、正しく動作していないように見える問題を見つけた場合は、Waterline GitHub issues forumに投稿してください。

于 2014-04-07T05:06:36.780 に答える