diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index f968e2cff..c84e58f75 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -594,7 +594,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { $this->_parseRules(); if ($rule === null) { unset($this->_fields[$field]); - } else { + } elseif (array_key_exists($field, $this->_fields)) { $this->_fields[$field]->removeRule($rule); } return $this; diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index e1984b219..7886fdd75 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -2007,6 +2007,9 @@ class ModelValidationTest extends BaseModelTest { $this->assertTrue(isset($Validator['other'])); $this->assertFalse(isset($Validator['other']['numeric'])); $this->assertTrue(isset($Validator['other']['between'])); + + $Validator->remove('other'); + $Validator->remove('other', 'between'); } /**