Skip to content

Validator - not able to add multiple rules at once for a single field #956

Closed
wants to merge 1 commit into from

3 participants

@the-tsc
the-tsc commented Nov 13, 2012

Set rules as CakeValidationRule and not plain array
http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3367

@dereuromark dereuromark commented on the diff Nov 13, 2012
lib/Cake/Model/Validator/CakeValidationSet.php
@@ -235,10 +235,11 @@ public function removeRule($name) {
* @return ModelField
*/
public function setRules($rules = array(), $mergeVars = true) {
- if ($mergeVars === false) {
- $this->_rules = $rules;
- } else {
- $this->_rules = array_merge($this->_rules, $rules);
+ if($mergeVars === false) {
@dereuromark
CakePHP member
dereuromark added a note Nov 13, 2012

missing space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ADmad
CakePHP member
ADmad commented Nov 13, 2012

CakeValidationSet::setRules() can already take multiple rules per field as shown in docblock

@ADmad ADmad closed this Nov 13, 2012
@the-tsc
the-tsc commented Nov 13, 2012

But its broken because $_rules holds CakeValidationRule objects and not arrays.

@ADmad
CakePHP member
ADmad commented Nov 13, 2012

Hmm, I will check. It's strange there are also tests for adding multiple rules through ModelValidator::add() which pass.

@ADmad ADmad reopened this Nov 13, 2012
@ADmad
CakePHP member
ADmad commented Nov 13, 2012

Yip the tests are incorrect or should I say incomplete. It only checks the key and fails to check that value should also be instance of CakeValidationRule.

@the-tsc Apologies for closing your PR prematurely.

@ADmad
CakePHP member
ADmad commented Nov 13, 2012

Fixed in ac087ec with tests. Thanks for the bug report and patch.

@ADmad ADmad closed this Nov 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.