Skip to content

Commit

Permalink
Use constants from ReferentialAction class
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Feb 10, 2025
1 parent 36275f2 commit 6418283
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Oracle\Column;

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder;
use Yiisoft\Db\Schema\Column\ColumnInterface;

Expand Down Expand Up @@ -51,8 +52,8 @@ public function build(ColumnInterface $column): string
protected function buildOnDelete(string $onDelete): string
{
return match ($onDelete = strtoupper($onDelete)) {
'CASCADE',
'SET NULL' => " ON DELETE $onDelete",
ReferentialAction::CASCADE,
ReferentialAction::SET_NULL => " ON DELETE $onDelete",
default => '',
};
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Oracle\Column\ColumnBuilder;
Expand Down Expand Up @@ -243,10 +244,12 @@ public static function buildColumnDefinition(): array
$referenceRestrict = new ForeignKeyConstraint();
$referenceRestrict->foreignColumnNames(['id']);
$referenceRestrict->foreignTableName('ref_table');
$referenceRestrict->onDelete('restrict');
$referenceRestrict->onDelete(ReferentialAction::RESTRICT);
$referenceRestrict->onUpdate(ReferentialAction::RESTRICT);

$referenceSetNull = clone $referenceRestrict;
$referenceSetNull->onDelete('set null');
$referenceSetNull->onDelete(ReferentialAction::SET_NULL);
$referenceRestrict->onUpdate(ReferentialAction::SET_NULL);

$values = parent::buildColumnDefinition();

Expand Down

0 comments on commit 6418283

Please sign in to comment.