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 22c5cb7 commit a56dadb
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 @@ -90,8 +90,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 @@ -124,8 +125,8 @@ private function performJoin($builder, $relations)
$keyRelated = $relatedRelation->getForeignKey();
$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 @@ -134,8 +135,9 @@ private function performJoin($builder, $relations)
}
}

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

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

0 comments on commit a56dadb

Please sign in to comment.