Skip to content

Commit

Permalink
fix HasOneJoin current table primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
fico7489 committed Feb 23, 2018
1 parent ca608bb commit adc6c57
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Traits/EloquentJoinTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ private function performJoin($builder, $relations)
$baseTable = $this->getTable();
$baseModel = $this;

$currentTable = $this->getTable();
$currentModel = $this;
$currentPrimaryKey = $this->getKeyName();
$currentTable = $this->getTable();

foreach ($relations as $relation) {
if ($relation == $column) {
Expand Down Expand Up @@ -122,8 +123,8 @@ private function performJoin($builder, $relations)
$keyRelated = $relatedRelation->getQualifiedForeignKeyName();
$keyRelated = last(explode('.', $keyRelated));

$builder->leftJoin($joinQuery, function ($join) use ($relatedTableAlias, $keyRelated, $currentTable, $relatedPrimaryKey, $relatedModel) {
$join->on($relatedTableAlias . '.' . $keyRelated, '=', $currentTable . '.' . $relatedPrimaryKey);
$builder->leftJoin($joinQuery, function ($join) use ($relatedTableAlias, $keyRelated, $currentTable, $relatedPrimaryKey, $relatedModel, $currentPrimaryKey) {
$join->on($relatedTableAlias . '.' . $keyRelated, '=', $currentTable . '.' . $currentPrimaryKey);

$this->leftJoinQuery($join, $relatedModel, $relatedTableAlias);
});
Expand All @@ -132,8 +133,9 @@ private function performJoin($builder, $relations)
}
}

$currentTable = $relatedTableAlias;
$currentModel = $relatedModel;
$currentPrimaryKey = $relatedPrimaryKey;
$currentTable = $relatedTableAlias;

$this->joinedTables[$relation] = $relatedTableAlias;
}
Expand Down

0 comments on commit adc6c57

Please sign in to comment.