Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 9, 2024
1 parent 704df9c commit 4796bdf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/QueryBuilder/AbstractColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,26 @@ protected function buildReferenceDefinition(ColumnSchemaInterface $column): stri
}

if (null !== $onDelete = $reference?->getOnDelete()) {
$sql .= ' ON DELETE ' . $onDelete;
$sql .= $this->buildOnDeleteClause($onDelete);
}

if (null !== $onUpdate = $reference?->getOnUpdate()) {
$sql .= ' ON UPDATE ' . $onUpdate;
$sql .= $this->buildOnUpdateClause($onUpdate);
}

return $sql;
}

protected function buildOnDeleteClause(string $onDelete): string
{
return " ON DELETE $onDelete";
}

protected function buildOnUpdateClause(string $onUpdate): string
{
return " ON UPDATE $onUpdate";
}

/**
* Builds the type definition for the column. For example: `varchar(128)` or `decimal(10,2)`.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,9 @@ public static function buildColumnDefinition(): array
$reference->onDelete('CASCADE');
$reference->onUpdate('CASCADE');

$referenceWithSchema = clone $reference;
$referenceWithSchema->foreignSchemaName('ref_schema');

return [
PseudoType::PK => ['integer PRIMARY KEY AUTO_INCREMENT', PseudoType::PK],
PseudoType::UPK => ['integer UNSIGNED PRIMARY KEY AUTO_INCREMENT', PseudoType::UPK],
Expand Down Expand Up @@ -1679,6 +1682,15 @@ public static function buildColumnDefinition(): array
),
ColumnBuilder::integer()->reference($reference),
],
'reference($referenceWithSchema)' => [
DbHelper::replaceQuotes(
<<<SQL
integer REFERENCES [[ref_schema]].[[ref_table]] ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE
SQL,
static::$driverName,
),
ColumnBuilder::integer()->reference($referenceWithSchema),
],
];
}
}

0 comments on commit 4796bdf

Please sign in to comment.