Skip to content

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