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.7] Fix self-referencing HasManyThrough existence queries #26662

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [];
}