Skip to content

Instantly share code, notes, and snippets.

@wprater
Last active January 4, 2016 04:49
Show Gist options
  • Save wprater/8571047 to your computer and use it in GitHub Desktop.
Save wprater/8571047 to your computer and use it in GitHub Desktop.
this.findById(ownerId)
// .lean()
.select('contacts')
.populate('contacts.person', 'id email avatar name nestedModel')
// FIXME feels like we should be able to get nested populations instead
// on building them inside the promise.
// .populate('contacts.person.nestedModel')
.exec()
.then(function (doc) {
NestedModel.populate(doc.contacts, {
path: 'person.nestedModel',
// FIXME this is still returning expired Flares.
options: {
sort: {updatedAt: -1},
}
}, function (err, contacts) {
// The contacts are populated correctly with the proper nestedModel
console.log(contacts);
contacts.forEach(function (rec) {
// This will log the person
console.log('person', rec.person.toJSON());
rec.person.toJSON({transform: function (doc, ret) {
// It's the nested model instead of the person object expected.
console.log('not the person!?', doc);
}});
});
});
}, function (err) {
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment