It seems to me that the model validation is somewhat flawed - let me
explain:

if I have a model with say three fields and I set up
var $validate = array (
                              'field1' => VAILID_NOT_EMPTY,
                              'field2' => VAILID_NOT_EMPTY,
                              'field3' => VAILID_NOT_EMPTY);

Validation works as I would expect ONLY if the data I am trying to save
has all three fields. i.e. if the data I am saving looks like :
$data = array
('field1'=>'somedata','field2'=>'somedata','field3'=>'somedata');

However if I try saving to the model with the data looking like say:
$data = array('field1'=>'somedata');
IT WORKS JUST FINE - EVEN THOUGH THERE IS NO DATA FOR field2 and field3
which is clearly not the intention of the business logic encapsulated
in $validate.

I checked through the code in model_php5.php the function invalidFields
the code that checks the fields is:

if (isset($data[$field_name]) && !preg_match($validator,
$data[$field_name])) {
                                $this->invalidate($field_name);
                        }

I.E. It only checks if data is valid IF the data field was submitted.
Is this the intention? If it is then the validation rules cannot be
considered business logic rules for the MODEL as they are easily
violated by simply submitting data with only some of the data fields
present.

Maybe something more like:
if (!isset($data[$field_name]) || (isset($data[$field_name]) &&
!preg_match($validator, $data[$field_name]))) {

                                $this->invalidate($field_name);
                        }

This would invalidate a field if there was a valiadition rule for the
field_name even if $data[$field_name] did not exists - this would seem
more like the intended behaviour.

I am reasonably new to cake - about 6 weeks and  I think it is a great
framework - this is my first post to this group so hope it makes sense.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to