我有Category
模特:
Category:
...
articles: [{type:ObjectId, ref:'Article'}]
文章模型包含对的引用Account model
。
Article:
...
account: {type:ObjectId, ref:'Account'}
因此,使用填充的articles
类别模型将是:
{ //category
articles: //this field is populated
[ { account: 52386c14fbb3e9ef28000001, // I want this field to be populated
date: Fri Sep 20 2013 00:00:00 GMT+0400 (MSK),
title: 'Article 1' } ],
title: 'Category 1' }
问题是:如何填充已填充字段([articles])的子字段(帐户)?这是我现在的做法:
globals.models.Category
.find
issue : req.params.id
null
sort:
order: 1
.populate("articles") # this populates only article field, article.account is not populated
.exec (err, categories) ->
console.log categories
我知道在这里进行了讨论:猫鼬:填充一个已填充的字段,但未找到实际的解决方案
.populate({path : 'userId', populate : {path : 'reviewId'}}).exec(...)
似乎是递归逻辑,这很有意义。其作品!