Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Db/Table/ForeignKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public function setOptions(array $options)
throw new RuntimeException(sprintf('"%s" is not a valid foreign key option.', $option));
}

// handle $options['delete'] as $options['update']
// handle $options['delete'] and $options['update']
if ($option === 'delete') {
$this->setOnDelete($value);
$this->delete = $this->normalizeAction($value);
} elseif ($option === 'update') {
$this->setOnUpdate($value);
$this->update = $this->normalizeAction($value);
} elseif ($option === 'deferrable') {
$this->setDeferrableMode($value);
} else {
Expand Down
4 changes: 2 additions & 2 deletions templates/bake/element/add-foreign-keys.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
$this->foreignKey({{ columnsList | raw }})
->setReferencedTable('{{ constraint['references'][0] }}')
->setReferencedColumns({{ columnsReference | raw }})
->setOnDelete('{{ Migration.formatConstraintAction(constraint['delete']) | raw }}')
->setOnUpdate('{{ Migration.formatConstraintAction(constraint['update']) | raw }}')
->setDelete('{{ Migration.formatConstraintAction(constraint['delete']) | raw }}')
->setUpdate('{{ Migration.formatConstraintAction(constraint['update']) | raw }}')
->setName('{{ constraintName }}')
)
{%~ endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/bake/element/change-method-body.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
$this->foreignKey({{ columnsList | raw }})
->setReferencedTable('{{ constraint['references'][0] }}')
->setReferencedColumns({{ columnsReference | raw }})
->setOnDelete('{{ Migration.formatConstraintAction(constraint['delete']) | raw }}')
->setOnUpdate('{{ Migration.formatConstraintAction(constraint['update']) | raw }}')
->setDelete('{{ Migration.formatConstraintAction(constraint['delete']) | raw }}')
->setUpdate('{{ Migration.formatConstraintAction(constraint['update']) | raw }}')
->setName('{{ constraintName }}')
);
{%~ endif %}
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Db/Table/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public function testAddForeignKeyWithObject(): void
$key->setColumns('user_id')
->setReferencedTable('users')
->setReferencedColumns(['id'])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setOptions(['delete' => 'CASCADE', 'update' => 'CASCADE'])
->setName('fk_user_id'),
);

Expand Down
8 changes: 4 additions & 4 deletions tests/comparisons/Diff/default/the_diff_default_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public function up(): void
$this->foreignKey('user_id')
->setReferencedTable('users')
->setReferencedColumns('id')
->setOnDelete('RESTRICT')
->setOnUpdate('RESTRICT')
->setDelete('RESTRICT')
->setUpdate('RESTRICT')
->setName('categories_ibfk_1')
)
->update();
Expand Down Expand Up @@ -232,8 +232,8 @@ public function down(): void
$this->foreignKey('user_id')
->setReferencedTable('users')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('articles_ibfk_1')
)
->update();
Expand Down
12 changes: 6 additions & 6 deletions tests/comparisons/Diff/default/the_diff_default_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function up(): void
$this->foreignKey('user_id')
->setReferencedTable('users')
->setReferencedColumns('id')
->setOnDelete('RESTRICT')
->setOnUpdate('RESTRICT')
->setDelete('RESTRICT')
->setUpdate('RESTRICT')
)
->update();

Expand Down Expand Up @@ -114,8 +114,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
)
->update();

Expand Down Expand Up @@ -207,8 +207,8 @@ public function down(): void
$this->foreignKey('user_id')
->setReferencedTable('users')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
)
->update();

Expand Down
4 changes: 2 additions & 2 deletions tests/comparisons/Diff/simple/the_diff_simple_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function up(): void
$this->foreignKey('user_id')
->setReferencedTable('users')
->setReferencedColumns('id')
->setOnDelete('RESTRICT')
->setOnUpdate('RESTRICT')
->setDelete('RESTRICT')
->setUpdate('RESTRICT')
->setName('articles_ibfk_1')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -387,8 +387,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -398,8 +398,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -327,8 +327,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -338,8 +338,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -327,8 +327,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -338,8 +338,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ public function change(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -327,8 +327,8 @@ public function change(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -338,8 +338,8 @@ public function change(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -368,8 +368,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -379,8 +379,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -308,8 +308,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -319,8 +319,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -308,8 +308,8 @@ public function up(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -319,8 +319,8 @@ public function up(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public function change(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('NO_ACTION')
->setOnUpdate('NO_ACTION')
->setDelete('NO_ACTION')
->setUpdate('NO_ACTION')
->setName('articles_category_fk')
)
->update();
Expand All @@ -308,8 +308,8 @@ public function change(): void
'category_id',
'id',
])
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('orders_product_fk')
)
->update();
Expand All @@ -319,8 +319,8 @@ public function change(): void
$this->foreignKey('category_id')
->setReferencedTable('categories')
->setReferencedColumns('id')
->setOnDelete('CASCADE')
->setOnUpdate('CASCADE')
->setDelete('CASCADE')
->setUpdate('CASCADE')
->setName('products_category_fk')
)
->update();
Expand Down
Loading
Loading