Skip to content

Commit

Permalink
Fix self-referencing HasManyThrough existence queries (#26662)
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir authored and taylorotwell committed Nov 29, 2018
1 parent 453317f commit 2ffac16
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder
{
$query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

$query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondLocalKey);
$query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondKey);

if ($this->throughParentSoftDeletes()) {
$query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Database/EloquentHasManyThroughTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_basic_create_and_retrieve()
{
$user = User::create(['name' => str_random()]);

$team1 = Team::create(['owner_id' => $user->id]);
$team1 = Team::create(['id' => 10, 'owner_id' => $user->id]);
$team2 = Team::create(['owner_id' => $user->id]);

$mate1 = User::create(['name' => str_random(), 'team_id' => $team1->id]);
Expand Down Expand Up @@ -127,5 +127,5 @@ class Team extends Model
{
public $table = 'teams';
public $timestamps = false;
protected $guarded = ['id'];
protected $guarded = [];
}

0 comments on commit 2ffac16

Please sign in to comment.