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.8] Fix self-referencing MorphOneOrMany existence queries #29765

Merged
merged 1 commit into from
Aug 27, 2019
Merged

[5.8] Fix self-referencing MorphOneOrMany existence queries #29765

merged 1 commit into from
Aug 27, 2019

Conversation

staudenmeir
Copy link
Contributor

Self-referencing existence queries of MorphOneOrMany relationships are incorrect:

class Comment extends Model
{
    public function replies()
    {
        return $this->morphMany(self::class, 'commentable');
    }
}

Comment::has('replies')->get();
# expected
select * from `comments` where exists (
  select * from `comments` as `laravel_reserved_0`
  where `comments`.`id` = `laravel_reserved_0`.`commentable_id`
  and `laravel_reserved_0`.`commentable_type` = ?
)

# actual
select * from `comments` where exists (
  select * from `comments` as `laravel_reserved_0`
  where `comments`.`id` = `laravel_reserved_0`.`commentable_id`
  and `comments`.`commentable_type` = ?
)      ^^^^^^^^

@taylorotwell taylorotwell merged commit 7d2a5d0 into laravel:5.8 Aug 27, 2019
@staudenmeir staudenmeir deleted the morph-existence branch August 27, 2019 20:03
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