【发布时间】:2019-09-01 05:02:48
【问题描述】:
我查看了很多旧的 SO 问题,它们破坏了 GitHub 链接和 SailsJS Trello,但我仍然不清楚。
是否可以在 SailsJS 中填充字段(一对一关系)并仅返回特定字段(通过选择或省略)。
await Document.find({id: id}).populate('createdBy', {select: ['name']})
我来了
UsageError: Invalid populate(s).
Details:
Could not populate `createdBy` 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!
(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense. This usage will be supported in a future version of Waterline.)
Here's what was passed in:
{ select: [ 'name' ] }
在模型中,
createdBy: {
model: 'user',
description: 'Who is this document assigned to'
},
我正在使用风帆1.1.0,水线0.13.5-0
我这样做对吗?有没有办法做到这一点?
【问题讨论】: