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

[5.2] Fix morphTo macro calls #13828

Merged
merged 1 commit into from Jun 2, 2016
Merged

[5.2] Fix morphTo macro calls #13828

merged 1 commit into from Jun 2, 2016

Conversation

acasar
Copy link
Contributor

@acasar acasar commented Jun 2, 2016

This fixes another edge case, where we want to call a query macro (like withTrashed, onlyTrashed) on a morphTo relation, but the macro only exists on the related model.

Before we had a hack that only handled withTrashed calls (https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Relations/MorphTo.php#L240:L267) now I generalized the idea, so that all macro calls are captured and replayed when we have an actual related instance.

/**
* Replay stored macro calls on the actual related instance.
*
* @param Builder $query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fqcn please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.

@dwightwatson
Copy link
Contributor

Thanks @acasar, this fixes the issue I mentioned in the comments of #13724 (see here).

I'd put together an example app that demonstrates the issue (and how it arose in 5.2.34) but this PR restores earlier working functionality. I'm still happy to upload this app if it will be of use.

@acasar
Copy link
Contributor Author

acasar commented Jun 2, 2016

@dwightwatson glad that it works for you.

What we had before was actually a hack that only handled withTrashed calls. With this PR any query macro is handled correctly.

@taylorotwell
Copy link
Member

Does this bug apply to any other relationships or just MorphTo?

@taylorotwell taylorotwell merged commit 4811209 into laravel:5.2 Jun 2, 2016
@dwightwatson
Copy link
Contributor

Seems to be working on other relationships to me. We use withTrashed() all over the place and only saw it break on MorphTo. 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.

None yet

4 participants