Skip to content

Commit c74a84b

Browse files
authored
Use constants from ReferentialAction class (#302)
1 parent 36275f2 commit c74a84b

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Enh #279: Separate column type constants (@Tigrov)
1616
- New #280, #291: Realize `ColumnBuilder` class (@Tigrov)
1717
- Enh #281: Update according changes in `ColumnSchemaInterface` (@Tigrov)
18-
- New #282, #291, #299: Add `ColumnDefinitionBuilder` class (@Tigrov)
18+
- New #282, #291, #299, #302: Add `ColumnDefinitionBuilder` class (@Tigrov)
1919
- Bug #285: Fix `DMLQueryBuilder::insertBatch()` method (@Tigrov)
2020
- Enh #283: Refactor `Dsn` class (@Tigrov)
2121
- Enh #286: Use constructor to create columns and initialize properties (@Tigrov)

src/Column/ColumnDefinitionBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Yiisoft\Db\Oracle\Column;
66

77
use Yiisoft\Db\Constant\ColumnType;
8+
use Yiisoft\Db\Constant\ReferentialAction;
89
use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder;
910
use Yiisoft\Db\Schema\Column\ColumnInterface;
1011

@@ -51,8 +52,8 @@ public function build(ColumnInterface $column): string
5152
protected function buildOnDelete(string $onDelete): string
5253
{
5354
return match ($onDelete = strtoupper($onDelete)) {
54-
'CASCADE',
55-
'SET NULL' => " ON DELETE $onDelete",
55+
ReferentialAction::CASCADE,
56+
ReferentialAction::SET_NULL => " ON DELETE $onDelete",
5657
default => '',
5758
};
5859
}

src/Schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Throwable;
88
use Yiisoft\Db\Cache\SchemaCache;
99
use Yiisoft\Db\Connection\ConnectionInterface;
10+
use Yiisoft\Db\Constant\ReferentialAction;
1011
use Yiisoft\Db\Constraint\CheckConstraint;
1112
use Yiisoft\Db\Constraint\Constraint;
1213
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
@@ -58,8 +59,7 @@
5859
* foreign_table_schema: string|null,
5960
* foreign_table_name: string|null,
6061
* foreign_column_name: string|null,
61-
* on_update: string,
62-
* on_delete: string,
62+
* on_delete: ReferentialAction::*,
6363
* check_expr: string
6464
* }
6565
* >

tests/Provider/QueryBuilderProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88
use Yiisoft\Db\Constant\ColumnType;
99
use Yiisoft\Db\Constant\PseudoType;
10+
use Yiisoft\Db\Constant\ReferentialAction;
1011
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
1112
use Yiisoft\Db\Expression\Expression;
1213
use Yiisoft\Db\Oracle\Column\ColumnBuilder;
@@ -243,10 +244,12 @@ public static function buildColumnDefinition(): array
243244
$referenceRestrict = new ForeignKeyConstraint();
244245
$referenceRestrict->foreignColumnNames(['id']);
245246
$referenceRestrict->foreignTableName('ref_table');
246-
$referenceRestrict->onDelete('restrict');
247+
$referenceRestrict->onDelete(ReferentialAction::RESTRICT);
248+
$referenceRestrict->onUpdate(ReferentialAction::RESTRICT);
247249

248250
$referenceSetNull = clone $referenceRestrict;
249-
$referenceSetNull->onDelete('set null');
251+
$referenceSetNull->onDelete(ReferentialAction::SET_NULL);
252+
$referenceRestrict->onUpdate(ReferentialAction::SET_NULL);
250253

251254
$values = parent::buildColumnDefinition();
252255

0 commit comments

Comments
 (0)