Skip to content

Commit

Permalink
Update RelationMixin.php
Browse files Browse the repository at this point in the history
fix HasManyThrough bug when parentQuery table is same of throughParent table
  • Loading branch information
biiiiiigmonster authored Dec 28, 2020
1 parent 38630a2 commit 1792bde
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Database/Eloquent/RelationMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ public function getRelationInQuery(): Closure
$hasManyThrough = function (Builder $query, Builder $parentQuery, $columns = ['*']): Builder{
/** @var HasManyThrough $this */
$columns = $columns == ['*'] ? $this->getQualifiedFirstKeyName() : $columns;
// if ($parentQuery->getQuery()->from === $query->getQuery()->from) {
// TODO
// return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
// }
if ($parentQuery->getQuery()->from === $this->throughParent->getTable()) {
$table = $this->throughParent->getTable().' as '.$hash = $this->getRelationCountHash();

// if ($parentQuery->getQuery()->from === $this->throughParent->getTable()) {
// TODO
// return $this->getRelationExistenceQueryForThroughSelfRelation($query, $parentQuery, $columns);
// }
$query->join($table, $hash.'.'.$this->secondLocalKey, '=', $this->getQualifiedFarKeyName());

if ($this->throughParentSoftDeletes()) {
$query->whereNull($hash.'.'.$this->throughParent->getDeletedAtColumn());
}

return $query->select($columns);
}

$this->performJoin($query);

Expand Down

0 comments on commit 1792bde

Please sign in to comment.