在将数据填充为值后的Sails.js v0.10中,我得到[Getter / Setter]

时间:2014-04-02 20:28:14

标签: mongodb sails.js waterline

填充数据后,我得到的结果与预期不符。

示例:

//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

sails-mongo:0.10.0-rc2

1 个答案:

答案 0 :(得分:1)

这些是使用console.log时的预期结果!如果要查看展开的对象,请执行以下操作:

console.log(res[0].toObject());