Last active
January 4, 2016 04:49
-
-
Save wprater/8571047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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