Skip to content

Commit b1cc11a

Browse files
[7.x] Add helper for on update cascade (#33522)
* add helper for on update cascade * Update ForeignKeyDefinition.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 09a7f4d commit b1cc11a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Illuminate/Database/Schema/ForeignKeyDefinition.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
*/
1515
class ForeignKeyDefinition extends Fluent
1616
{
17+
/**
18+
* Indicate that updates should cascade.
19+
*
20+
* @return $this
21+
*/
22+
public function cascadeOnUpdate()
23+
{
24+
return $this->onUpdate('cascade');
25+
}
26+
1727
/**
1828
* Indicate that deletes should cascade.
1929
*

tests/Database/DatabaseMySqlSchemaGrammarTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ public function testAddingForeignKey()
388388

389389
$this->assertCount(1, $statements);
390390
$this->assertSame('alter table `users` add constraint `users_foo_id_foreign` foreign key (`foo_id`) references `orders` (`id`) on delete cascade', $statements[0]);
391+
392+
$blueprint = new Blueprint('users');
393+
$blueprint->foreign('foo_id')->references('id')->on('orders')->cascadeOnUpdate();
394+
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
395+
396+
$this->assertCount(1, $statements);
397+
$this->assertSame('alter table `users` add constraint `users_foo_id_foreign` foreign key (`foo_id`) references `orders` (`id`) on update cascade', $statements[0]);
391398
}
392399

393400
public function testAddingIncrementingID()

0 commit comments

Comments
 (0)