Skip to content

Conversation

@stolzda
Copy link

@stolzda stolzda commented Oct 10, 2016

The problem when reverse populating a model is that the returned object hierarchy is not consistent.

Example:
Two authors:
{name: "A", _id: 1} , {name: "B", _id: 2}

Two books:
{name: "book1", author: 1}, {name: "book2", author: 1}

Reverse population of authors with books gives you:

[ { name: "A", _id: 1, books: [{name: "book1", author: 1}, {name: "book2", author: 1}] },
{ name: "B", _id: 2} ]

With the new optional argument "addEmptyObject" set to true it gives you:

[ { name: "A", _id: 1, books: [{name: "book1", author: 1}, {name: "book2", author: 1}] },
{ name: "B", _id: 2, books: [] } ]

I.e., the author object is kept consistent (every author has the field books).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant