填充数据后,我得到的结果不符合预期。
例子:
//User.js Model
module.exports = {
attributes: {
//"id" attribute is here primary key by default
schools: { collection: 'School', via: 'id' },
name: { type: 'String', trim: true, required: true }
}
}
这是我的 School.js
//School.js Model
module.exports = {
attributes: {
//"id" attribute is here primary key by default
name: { type: 'String', trim: true, required: true },
}
}
我的用户实体数据如下所示:
//User document in MongoDB
{
_id: 1,
name: "Foo",
schools: [1,2,3]
}
我的学校实体数据如下所示:
//School documents in MongoDB
{
_id: 1,
name: "School 1"
}
{
_id: 2,
name: "School 2"
}
{
_id: 3,
name: "School 3"
}
现在我想填充学校。我这样做:
User.find().populate("schools").exec(function(err, res){ console.log(res[0]) });
这就是我得到的结果:
{
schools: [Getter/Setter],
name: "Foo",
id: 1
}
预期的:
{
schools: [
{id: 1, name: "School 1"},
{id: 2, name: "School 2"},
{id: 3, name: "School 3"}
],
name: "Foo",
id: 1
}
我怎样才能得到预期的结果?
我使用 MongoDB 作为数据存储。
版本:
Sails.js:v0.10.0-rc5
水线:v0.10.0-rc7
帆蒙戈:0.10.0-rc2