Friday, October 29, 2010

Using the same validation method for create and update modes

Hello, I thought I was being clever by defining a custom validation
method called validateUploadedFileExtensions which accepts a couple or
parameters. In my Image model's validation I would then reuse this
method for two rules for a model's field, like this:
'image' => array(
'imageExtension' => array(
'rule' => array('validateUploadedFileExtensions', 'image', true),
'message' => 'Invalid image extension',
'last' => false,
'on' => 'create'
),
'imageExtension' => array(
'rule' => array('validateUploadedFileExtensions', 'image', false),
'message' => 'Invalid image extension',
'last' => false,
'on' => 'update'
),
...

But, if I'm validating a collection of Image models as children to a
parent object, and some of the images are new (validating by create)
and some are updates (validating by update), only the validation for
creates are called. Is this a bug, or did they never intend for the
same validation method to be re-used like this?

Thanks in advance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: