Skip to content

Fixed partially populating multiple children of sub-documents.#639

Closed
kenpratt wants to merge 1 commit intoAutomattic:masterfrom
kenpratt:fixed_population_on_subdocuments
Closed

Fixed partially populating multiple children of sub-documents.#639
kenpratt wants to merge 1 commit intoAutomattic:masterfrom
kenpratt:fixed_population_on_subdocuments

Conversation

@kenpratt
Copy link
Copy Markdown
Contributor

@kenpratt kenpratt commented Dec 7, 2011

I ran into some issues with populating sub-documents -- namely, if you issue more than one populate request in the query, the settings for the populate requests clobber each other (with the last one taking precedence).

For example:

query.populate('kids.user', ["name"]).populate('kids.post', ["title"])

Would populate the kids.post fine but not populate name on kids.user. (title would be present on kids.user if user happened to have that field).

Same for conditions:

query.populate('kids.user', ["name"]).populate('kids.post', ["title"], { title: "woot" })

Would result in no kids.user fields being populated, since none match the condition on kids.post.

I fixed it by saving the query parameters for each sub-path instead of just storing the first query paramaters found and marking sub-paths as existent.

@aheckmann
Copy link
Copy Markdown
Collaborator

nice find! when I get access to real internet I'll test/merge it in.

thanks Ken!

On Dec 6, 2011, at 11:39 PM, Ken Prattreply@reply.github.com wrote:

I ran into some issues with populating sub-documents -- namely, if you issue more than one populate request in the query, the settings for the populate requests clobber each other (with the last one taking precedence).

For example:

query.populate('kids.user', ["name"]).populate('kids.post', ["title"])

Would populate the kids.post fine but not populate name on kids.user. (title would be present on kids.user if user happened to have that field).

Same for conditions:

query.populate('kids.user', ["name"]).populate('kids.post', ["title"], { title: "woot" })

Would result in no kids.user fields being populated, since none match the condition on kids.post.

I fixed it by saving the query parameters for each sub-path instead of just storing the first query paramaters found and marking sub-paths as existent.

You can merge this Pull Request by running:

git pull https://github.com/kenpratt/mongoose fixed_population_on_subdocuments

Or you can view, comment on it, or merge it online at:

#639

-- Commit Summary --

  • Fixed partially populating multiple children of sub-documents.

-- File Changes --

M lib/model.js (7)
M test/model.ref.test.js (66)

-- Patch Links --

https://github.com/LearnBoost/mongoose/pull/639.patch
https://github.com/LearnBoost/mongoose/pull/639.diff


Reply to this email directly or view it on GitHub:
#639

@aheckmann
Copy link
Copy Markdown
Collaborator

merged thanks!

@aheckmann aheckmann closed this Dec 8, 2011
@kenpratt
Copy link
Copy Markdown
Contributor Author

kenpratt commented Dec 8, 2011

Awesome, thanks.

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.

2 participants