Skip to content

Commit

Permalink
Merge pull request #232 from thecodingmachine/feature/fix-pivot-table…
Browse files Browse the repository at this point in the history
…-name

Fix ORA-00905 for pivot table: Oracle cannot alias joined tables
  • Loading branch information
homersimpsons committed Oct 7, 2020
2 parents 58b14a5 + 16ad42f commit 4beb009
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Utils/ManyToManyRelationshipPathDescriptor.php
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 4beb009

Please sign in to comment.