Skip to content

Commit

Permalink
Fix ORA-00905 for pivot table: Oracle cannot alias joined tables
Browse files Browse the repository at this point in the history
  • Loading branch information
homersimpsons committed Oct 7, 2020
1 parent 58b14a5 commit 16ad42f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Utils/ManyToManyRelationshipPathDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(string $targetTable, string $pivotTable, array $join

public static function generateModelKey(ForeignKeyConstraint $remoteFk, ForeignKeyConstraint $localFk): string
{
return $remoteFk->getLocalTableName().".".implode("__", $localFk->getUnquotedLocalColumns());
return $remoteFk->getLocalTableName() . "." . implode("__", $localFk->getUnquotedLocalColumns());
}

public function getPivotName(): string
Expand All @@ -68,19 +68,19 @@ public function getPivotFrom(): string

$join = [];
foreach ($this->joinForeignKeys as $key => $column) {
$join[] = $mainTable.'.'.$column.' = pivot.'.$this->joinLocalKeys[$key];
$join[] = sprintf('%s.%s = %s.%s', $mainTable, $column, $pivotTable, $this->joinLocalKeys[$key]);
}

return $mainTable.' JOIN '.$pivotTable.' pivot ON '.implode(' AND ', $join);
return $mainTable . ' JOIN ' . $pivotTable . ' ON ' . implode(' AND ', $join);
}

public function getPivotWhere(): string
{
$paramList = [];
foreach ($this->whereKeys as $key => $column) {
$paramList[] = ' pivot.'.$column." = :param$key";
$paramList[] = sprintf('%s.%s = :param%s', $this->pivotTable, $column, $key);
}
return implode(" AND ", $paramList);
return implode(' AND ', $paramList);
}

/**
Expand All @@ -91,7 +91,7 @@ public function getPivotParams(array $primaryKeys): array
{
$params = [];
foreach ($primaryKeys as $key => $primaryKeyValue) {
$params["param$key"] = $primaryKeyValue;
$params['param' . $key] = $primaryKeyValue;
}
return $params;
}
Expand Down

0 comments on commit 16ad42f

Please sign in to comment.