I cannot seem to get an array to validate properly: in my example, every musician must have at least one instrument ($musician->instruments is an array of instruments). I have tried setting up validation rules in the following ways, but none of them validate under any circumstances (including when the array has at least one value).
A
public $validates = array(
'name' => 'Required',
'instruments' => 'Required'
);
B
public $validates = array(
'name' => 'Required',
'instruments' => array(
array(
'notEmpty',
'message' => 'Required'
)
)
);
even C fails to validate
Validator::add('hasAtLeastOne', function($value) {
return true;
});
...
public $validates = array(
'name' => 'Required',
'instruments' => array(
array(
'hasAtLeastOne',
'message' => 'Required'
)
)
);
How do you set it up so that if the validator fails if the array is empty, and passes if count($musician->instruments) >= 1?