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

Conversation

@staudenmeir
Copy link
Contributor

commented Aug 27, 2019

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@staudenmeir staudenmeir deleted the staudenmeir:morph-existence branch Aug 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.