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.6] Throw exception for has() with MorphTo relationship #25337

Merged
merged 1 commit into from
Aug 26, 2018
Merged

[5.6] Throw exception for has() with MorphTo relationship #25337

merged 1 commit into from
Aug 26, 2018

Conversation

staudenmeir
Copy link
Contributor

It's a long-known issue that has() and whereHas() don't support MorphTo relationships (#5429, #18523). There are workarounds, but the fundamental problem is basically unfixable.

Depending on the actual code, the user gets an exception (e.g. "unknown column") or the query "successfully" executes pointless SQL:

Comment::has('commentable')->get();
select *
from "comments"
where exists (
  select *
  from "comments" as "laravel_reserved_0"
  where "laravel_reserved_0"."id" = "laravel_reserved_0"."commentable_id"
)

With this PR, the user at least receives a proper exception.
Should we include a link to one of the GitHub issues (for the workarounds)?

@taylorotwell taylorotwell merged commit 4ea7c05 into laravel:5.6 Aug 26, 2018
@staudenmeir staudenmeir deleted the where-has-morph-to branch August 26, 2018 16:11
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

2 participants