I was just under the assumption cake would handle that with saveAll since
there is nothing mentioning that it can't validate HABTM models. The "ALL"
in saveAll makes it sounds like it would save all related data.
$this->Post->saveAll( $this->data, array('validate' => 'only') ) to me
sounds like " if all of this data were to validate it could all be saved".
Post is related to Category HABTM relation and the book says save related
data in 1 call (db supports that is) if it validates.
Not being an ass but that sounds like saveSome() if your validating it
first.....no?
-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Jeremy Burns | Class Outfit
Sent: Friday, April 01, 2011 12:53 AM
To: cake-php@googlegroups.com
Subject: Re: Validate HABTM Multiple
Couldn't you write a custom validation rule in the Post model that examines
the count of the Category key of the data array passed in?
Jeremy Burns
Class Outfit
jeremyburns@classoutfit.com
http://www.classoutfit.com
On 1 Apr 2011, at 01:18, Krissy Masters wrote:
> How can you validate the number of "multiple" selected?
>
> I have a Post which hasMany, and HABTM relations so saving with :
>
> if ( $this->Post->saveAll( $this->data, array('validate' => 'only') ) )
> {//only testing to get errors
>
> but I never get any validation errors for the HABTM model
>
> Category:
> public $validate = array(
>
> 'Category' => array(
> 'multiple' => array(
> 'required' => false,
> 'allowEmpty' => true,
> 'rule' => array(
> 'multiple', array('max' => 3),
> 'message' => 'Please select one, two or
> three options'))));
>
>
> Post HABTM Category
>
> Ideas?
>
> Thanks
>
> K
>
> --
> Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.
>
>
> 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
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.
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
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment