Sails.js对象在填充后有未定义的集合
每当我在Sails.js中填充一个集合,这些值都被填充到modelName.associations.collectionName.value
。 modelName.collectionName
的值modelName.collectionName
是未定义的,即使当我将对象表示为JSON时,所有内容都将完美显示。
以文档( http://sailsjs.org/#/documentation/concepts/ORM/Associations/ManytoMany.html )中给出的多对多关系为例,如果我执行以下查询:
User.findOne(1) .populate('pets') .exec(function(err, owner) {...});
我会得到owner.associations.pets.value
的宠物集合,但是owner.pets
是未定义的。
有什么想法发生在这里?
编辑:
我已经复制了文档中给出的完全相同的例子(相同的Pet.js
, User.js
和bootstrap.js
),我已经用这种方式覆盖了User.js
的findOne
蓝图:
findOne: function (req, res) { User.findOne(req.params.id) .populate('pets') .exec(function(err, owner) { if (err) return res.send(err, 500); return res.json(owner); }); }
正如我所料,JSON响应是好的,但如果我在exec(..)
函数内设置断点, owner.pets
是未定义的。 数据只在owner.associations.pets.value
。
难道是我的Sails.js版本吗? 这是0.10.0-rc11。