Sails.js: 由于用法不明确,无法填充模型
Sails.js: Could not populate model because of ambiguous usage
我有两个模型,比如说 A 和 B。这是一个 1:n 关系,其中一个 A 拥有一个 B,并且 B 可以是拥有我的多个 As.
现在,如果可能的话,B 不必知道它所引用的所有 A,所以我仅在 A 侧关联。
现在我想搜索所有拥有 B 的 A,并且符合特定条件。我基本上试过这个:
A.find()
.populate('B', {
where: {
someAttr: 1
}
})
查看文档,我发现这与示例非常相似 there。
现在我收到以下错误:
Could not populate B
because of ambiguous usage. This is a
singular ("model") association, which means it never refers to more
than one associated record. So passing in subcriteria (i.e. as the
second argument to .populate()
) is not supported for this
association, since it generally wouldn't make any sense. But that's
the trouble-- it looks like some sort of a subcriteria (or something)
was provided!
我能否在不给 B 返回对 A 的引用的情况下使这个查询工作?我觉得这是不必要的模型膨胀。
我现在正在使用 Sails 1.0.1。
正在研究 docs 关于 subcriteria
到 populate
的第二个参数:
When populating collection associations between two models which reside in the same database, a Waterline criteria may be specified as a second argument to populate. This will be used for filtering, sorting, and limiting the array of associated records (e.g. snacks) associated with EACH primary record.
执行此操作的一种方法是检索所有记录然后过滤它们,或者直接使用本机查询。
我有两个模型,比如说 A 和 B。这是一个 1:n 关系,其中一个 A 拥有一个 B,并且 B 可以是拥有我的多个 As.
现在,如果可能的话,B 不必知道它所引用的所有 A,所以我仅在 A 侧关联。
现在我想搜索所有拥有 B 的 A,并且符合特定条件。我基本上试过这个:
A.find()
.populate('B', {
where: {
someAttr: 1
}
})
查看文档,我发现这与示例非常相似 there。
现在我收到以下错误:
Could not populate
B
because of ambiguous usage. This is a singular ("model") association, which means it never refers to more than one associated record. So passing in subcriteria (i.e. as the second argument to.populate()
) is not supported for this association, since it generally wouldn't make any sense. But that's the trouble-- it looks like some sort of a subcriteria (or something) was provided!
我能否在不给 B 返回对 A 的引用的情况下使这个查询工作?我觉得这是不必要的模型膨胀。
我现在正在使用 Sails 1.0.1。
正在研究 docs 关于 subcriteria
到 populate
的第二个参数:
When populating collection associations between two models which reside in the same database, a Waterline criteria may be specified as a second argument to populate. This will be used for filtering, sorting, and limiting the array of associated records (e.g. snacks) associated with EACH primary record.
执行此操作的一种方法是检索所有记录然后过滤它们,或者直接使用本机查询。