From ce9f4f1db7c893a676289c5ec3745752b4ce7bd2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Mar 2012 10:33:06 -0500 Subject: [PATCH] Added support for on_delete and on_cascade of foreign keys. --- laravel/database/schema/grammars/grammar.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/laravel/database/schema/grammars/grammar.php b/laravel/database/schema/grammars/grammar.php index ad0dfbcc..1d3390a1 100644 --- a/laravel/database/schema/grammars/grammar.php +++ b/laravel/database/schema/grammars/grammar.php @@ -32,7 +32,22 @@ abstract class Grammar extends \Laravel\Database\Grammar { $sql = "ALTER TABLE $table ADD CONSTRAINT $name "; - return $sql .= "FOREIGN KEY ($foreign) REFERENCES $on ($referenced)"; + $sql .= "FOREIGN KEY ($foreign) REFERENCES $on ($referenced)"; + + // Finally we will check for any "on delete" or "on update" options for + // the foreign key. These control the behavior of the constraint when + // an update or delete statement is run against the record. + if ( ! is_null($command->on_delete)) + { + $sql .= " ON DELETE {$command->on_delete}"; + } + + if ( ! is_null($command->on_update)) + { + $sql .= " ON UPDATE {$command->on_update}"; + } + + return $sql; } /**