Permalink
Browse files

Rename options so they are all strings.

After some discussion we came up with better names for the constraint
options.
  • Loading branch information...
markstory committed Jun 7, 2013
1 parent 9dbeae0 commit c0f7ef87b172caaab7a1f10dcca68eb218c705a8
@@ -229,9 +229,9 @@ protected function _convertOnClause($clause) {
return strtolower($clause);
}
if ($clause === 'NO ACTION') {
return 'none';
return 'noAction';
}
return null;
return 'setNull';
}
/**
@@ -347,7 +347,7 @@ public function constraintSql(Table $table, $name) {
* @return string
*/
protected function _foreignOnClause($on) {
if ($on === null) {
if ($on === 'setNull') {
return 'SET NULL';
}
if ($on === 'cascade') {
@@ -356,7 +356,7 @@ protected function _foreignOnClause($on) {
if ($on === 'restrict') {
return 'RESTRICT';
}
if ($on === 'none') {
if ($on === 'noAction') {
return 'NO ACTION';
}
}
@@ -331,12 +331,12 @@ protected function _checkForeignKey($attrs) {
if (count($attrs['references']) < 2) {
throw new Exception(__d('cake_dev', 'References must contain a table and column.'));
}
$validActions = ['cascade', 'restrict', null, 'none'];
$validActions = ['cascade', 'restrict', 'setNull', 'noAction'];
if (!in_array($attrs['update'], $validActions)) {
throw new Exception(__d('cake_dev', 'Update action is invalid.'));
throw new Exception(__d('cake_dev', 'Update action is invalid. Must be one of %s', implode(',', $validActions)));
}
if (!in_array($attrs['delete'], $validActions)) {
throw new Exception(__d('cake_dev', 'Delete action is invalid.'));
throw new Exception(__d('cake_dev', 'Delete action is invalid. Must be one of %s', implode(',', $validActions)));
}
return $attrs;
}
@@ -493,13 +493,13 @@ public static function constraintSqlProvider() {
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => null],
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'setNull'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE SET NULL ON DELETE RESTRICT'
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'none'],
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'noAction'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT'
],

0 comments on commit c0f7ef8

Please sign in to comment.