Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Bugfix for calling pluck() on chaperoned relations. #52680

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

samlev
Copy link
Contributor

@samlev samlev commented Sep 6, 2024

Issue #52660 discovered an issue where calling $model->relationship()->pluck('foo') would fail on chaperoned relations, as the pluck() method sends only the selected field to the afterQuery() callback instead of the model.

This PR includes a failing test case, and a commit which resolves the issue by only attempting to hydrate the relationship on models in the callback, and skipping anything that's not a model.

Copy link

github-actions bot commented Sep 6, 2024

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

This test should fail if non-models are passed to
`applyInverseRelationToCollection()`, e.g. when
`pluck()` is called on a query.
@samlev samlev force-pushed the bugfix/11.x_52660_chaperone-pluck branch from 9cfaa9f to 47596a1 Compare September 6, 2024 13:34
@samlev samlev marked this pull request as ready for review September 6, 2024 13:37
@samlev
Copy link
Contributor Author

samlev commented Sep 6, 2024

@driesvints this one was pretty small, so not a big deal to push it up now. I didn't explicitly test pluck(), but I resolved the underlying issue.

I'm not sure what those test failures are about - they're nothing to do with what this PR touched.

The infinite recursion on $touches will have to be another PR, and can wait until next week when I'm back in front of my computer (I... may have done this PR from bed via an SSH client on my phone...)

@taylorotwell taylorotwell merged commit caec234 into laravel:11.x Sep 6, 2024
15 of 31 checks passed
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