Skip to content
Permalink
Browse files

Use constants instead of bare strings.

Constants feel better in code vs. bare strings. They also
cause errors when you make a mistake.
  • Loading branch information...
markstory committed Jun 7, 2013
1 parent c0f7ef8 commit 5d29549fb6aa5afb25b00b268dd14e5647e38bcb
Showing with 14 additions and 9 deletions.
  1. +6 −6 lib/Cake/Database/Schema/SqliteSchema.php
  2. +8 −3 lib/Cake/Database/Schema/Table.php
@@ -229,9 +229,9 @@ protected function _convertOnClause($clause) {
return strtolower($clause);
}
if ($clause === 'NO ACTION') {
return 'noAction';
return Table::ACTION_NO_ACTION;
}
return 'setNull';
return Table::ACTION_SET_NULL;
}
/**
@@ -347,16 +347,16 @@ public function constraintSql(Table $table, $name) {
* @return string
*/
protected function _foreignOnClause($on) {
if ($on === 'setNull') {
if ($on === Table::ACTION_SET_NULL) {
return 'SET NULL';
}
if ($on === 'cascade') {
if ($on === Table::ACTION_CASCADE) {
return 'CASCADE';
}
if ($on === 'restrict') {
if ($on === Table::ACTION_RESTRICT) {
return 'RESTRICT';
}
if ($on === 'noAction') {
if ($on === Table::ACTION_NO_ACTION) {
return 'NO ACTION';
}
}
@@ -125,6 +125,11 @@ class Table {
const INDEX_INDEX = 'index';
const INDEX_FULLTEXT = 'fulltext';
const ACTION_CASCADE = 'cascade';
const ACTION_SET_NULL = 'setNull';
const ACTION_NO_ACTION = 'noAction';
const ACTION_RESTRICT = 'restrict';
/**
* Constructor.
*
@@ -288,8 +293,8 @@ public function primaryKey() {
* - `type` The type of constraint being added.
* - `columns` The columns in the index.
* - `references` The table, column a foreign key references.
* - `update` The behavior on update. Options are 'restrict', `null`, 'cascade', 'none'.
* - `delete` The behavior on delete. Options are 'restrict', `null`, 'cascade', 'none'.
* - `update` The behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
* - `delete` The behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
*
* The default for 'update' & 'delete' is 'cascade'.
*
@@ -331,7 +336,7 @@ 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', 'setNull', 'noAction'];
$validActions = [static::ACTION_CASCADE, static::ACTION_RESTRICT, static::ACTION_SET_NULL, static::ACTION_NO_ACTION];
if (!in_array($attrs['update'], $validActions)) {
throw new Exception(__d('cake_dev', 'Update action is invalid. Must be one of %s', implode(',', $validActions)));
}

0 comments on commit 5d29549

Please sign in to comment.
You can’t perform that action at this time.