Skip to content

Commit 4beb009

Browse files
Merge pull request #232 from thecodingmachine/feature/fix-pivot-table-name
Fix ORA-00905 for pivot table: Oracle cannot alias joined tables
2 parents 58b14a5 + 16ad42f commit 4beb009

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Utils/ManyToManyRelationshipPathDescriptor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(string $targetTable, string $pivotTable, array $join
4848

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

5454
public function getPivotName(): string
@@ -68,19 +68,19 @@ public function getPivotFrom(): string
6868

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

74-
return $mainTable.' JOIN '.$pivotTable.' pivot ON '.implode(' AND ', $join);
74+
return $mainTable . ' JOIN ' . $pivotTable . ' ON ' . implode(' AND ', $join);
7575
}
7676

7777
public function getPivotWhere(): string
7878
{
7979
$paramList = [];
8080
foreach ($this->whereKeys as $key => $column) {
81-
$paramList[] = ' pivot.'.$column." = :param$key";
81+
$paramList[] = sprintf('%s.%s = :param%s', $this->pivotTable, $column, $key);
8282
}
83-
return implode(" AND ", $paramList);
83+
return implode(' AND ', $paramList);
8484
}
8585

8686
/**
@@ -91,7 +91,7 @@ public function getPivotParams(array $primaryKeys): array
9191
{
9292
$params = [];
9393
foreach ($primaryKeys as $key => $primaryKeyValue) {
94-
$params["param$key"] = $primaryKeyValue;
94+
$params['param' . $key] = $primaryKeyValue;
9595
}
9696
return $params;
9797
}

0 commit comments

Comments
 (0)