Skip to content

Commit ab1ec76

Browse files
committed
fix: Add prefix when adding foreign key
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 7dd9f40 commit ab1ec76

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/private/DB/Schema/Table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\Schema\SchemaException as DBALSchemaException;
1616
use Doctrine\DBAL\Schema\Table as DBALTable;
1717
use Doctrine\DBAL\Types\Type as DBALType;
18+
use OC\DB\Connection;
1819
use OCP\DB\Schema\ColumnType;
1920
use OCP\DB\Schema\IColumn;
2021
use OCP\DB\Schema\IForeignKeyConstraint;
@@ -27,7 +28,8 @@
2728
*/
2829
class Table implements ITable {
2930
public function __construct(
30-
private DBALTable $table,
31+
private readonly DBALTable $table,
32+
private readonly Connection $connection,
3133
) {
3234
}
3335

@@ -117,7 +119,7 @@ public function getPrimaryKey(): ?IIndex {
117119

118120
#[\Override]
119121
public function hasPrimaryKey(): bool {
120-
return $this->table->hasPrimaryKey();
122+
return $this->table->getPrimaryKey() !== null;
121123
}
122124

123125
#[\Override]
@@ -206,7 +208,7 @@ public function addForeignKeyConstraint(
206208
): self {
207209
try {
208210
$this->table->addForeignKeyConstraint(
209-
$foreignTable instanceof self ? $foreignTable->getWrappedTable() : $foreignTable,
211+
$foreignTable instanceof self ? $foreignTable->getWrappedTable() : $this->connection->getPrefix() . $foreignTable,
210212
$localColumnNames,
211213
$foreignColumnNames,
212214
$options,

lib/private/DB/SchemaWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getTableNames(): array {
7575
#[\Override]
7676
public function getTable(string $tableName): ITable {
7777
try {
78-
return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName));
78+
return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName), $this->connection);
7979
} catch (DBALSchemaException $e) {
8080
throw new SchemaException($e->getMessage(), $e->getCode(), $e);
8181
}

0 commit comments

Comments
 (0)