I'm getting some odd behaviour from Cake's validation code in
model_php5, version 1.1.18.5850
Consider the following case...
We have a model Event, which has the following validation rules:
var $validate = array(
'start' => VALID_NOT_EMPTY,
'end' => VALID_NOT_EMPTY
);
Let's try and save an event which is clearly not valid:
$this->Even->save(array('start' => null, 'end' => null));
Cake will actually claim that this event is valid - validates returns
true. So it will try to save to the database, which will generate a
database error if we have set up the table to not accept null values
in those fields.
This obviously doesn't seem right!
I think it's because if you look in the validation code below from the
invalidFields function (model_php5.php line 1350) - it will actually
not bother to validate if the field isn't "set". So since the field is
null Cake won't try to validate it.
foreach ($this->validate as $field_name => $validator) {
if (isset($data[$field_name]) && !preg_match($validator,
$data[$field_name])) {
$this->invalidate($field_name);
}
}
Am guessing this is because the functions are adapted to handle form
data, but this caused a real headache!
Comments?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---