RE: Validate HABTM Multiple

2011-04-04 Thread Krissy Masters
Yes I have the 'with' set in each model. Still the only way I get the errors
is by manually setting data to the Category Model. No luck with saveAll()

K

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of gremlin
Sent: Tuesday, April 05, 2011 2:05 AM
To: CakePHP
Subject: Re: Validate HABTM Multiple

Are you using the 'with' key in the model relationship? Are you doing
it in both directions? I don't know if it will help but I vaguely
remember something along these lines.

On Apr 3, 11:41 am, "Krissy Masters" 
wrote:
> Nothing. I simply want to first make sure no more than 5 are selected so I
> select 6 and submit.
>
> Debug data see 6
> Category Category array(
>         0 => 3
>         1 => 5
>         so on.)
>
> But no validation errors for Category. Just the Post...missing title,
> missing comment what not
>
> $this->Post->set($this->data);
>
> //Debug($this->Post->saveAll( $this->data, array('validate' => 'only')));
> $this->Post->saveAll( $this->data, array('validate' => 'only') )
>
> If I manually set data to the Category I get the messages saying too many
> selected so the validation in Category is set correct.
>
> I was just hoping saveAll would take care of this for me.
>
> I can wite validation anywhere set it to any model but figured why should
I
> have to since all should be all :) Not some.
>
> K
>
>
>
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On
Behalf
> Of euromark
> Sent: Sunday, April 03, 2011 9:07 AM
> To: CakePHP
> Subject: Re: Validate HABTM Multiple
>
> "but I never get any validation errors for the HABTM model "
>
> what does $this->Post->saveAll() return?
> boolean or array?
>
> pr() it pretty quick - I had similar issues I think
>
> On 1 Apr., 05:37, "Krissy Masters"  wrote:
> > I can, but why should I have to validate the Category in the Post model?
>
> > 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
>
> > jeremybu...@classoutfit.comhttp://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
> Tutorialshttp://tv.cakephp.org
> > > Check out the new CakePHP Qu

Re: Validate HABTM Multiple

2011-04-04 Thread gremlin
Are you using the 'with' key in the model relationship? Are you doing
it in both directions? I don't know if it will help but I vaguely
remember something along these lines.

On Apr 3, 11:41 am, "Krissy Masters" 
wrote:
> Nothing. I simply want to first make sure no more than 5 are selected so I
> select 6 and submit.
>
> Debug data see 6
> Category Category array(
>         0 => 3
>         1 => 5
>         so on.)
>
> But no validation errors for Category. Just the Post...missing title,
> missing comment what not
>
> $this->Post->set($this->data);
>
> //Debug($this->Post->saveAll( $this->data, array('validate' => 'only')));
> $this->Post->saveAll( $this->data, array('validate' => 'only') )
>
> If I manually set data to the Category I get the messages saying too many
> selected so the validation in Category is set correct.
>
> I was just hoping saveAll would take care of this for me.
>
> I can wite validation anywhere set it to any model but figured why should I
> have to since all should be all :) Not some.
>
> K
>
>
>
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
> Of euromark
> Sent: Sunday, April 03, 2011 9:07 AM
> To: CakePHP
> Subject: Re: Validate HABTM Multiple
>
> "but I never get any validation errors for the HABTM model "
>
> what does $this->Post->saveAll() return?
> boolean or array?
>
> pr() it pretty quick - I had similar issues I think
>
> On 1 Apr., 05:37, "Krissy Masters"  wrote:
> > I can, but why should I have to validate the Category in the Post model?
>
> > 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
>
> > jeremybu...@classoutfit.comhttp://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
> Tutorialshttp://tv.cakephp.org
> > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > others with their CakePHP related questions.
>
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php
>
> > --
> > Our newest site for the community: 

RE: Validate HABTM Multiple

2011-04-03 Thread Krissy Masters
Nothing. I simply want to first make sure no more than 5 are selected so I
select 6 and submit.

Debug data see 6 
Category Category array(
0 => 3
1 => 5
so on.)

But no validation errors for Category. Just the Post...missing title,
missing comment what not

$this->Post->set($this->data);

//Debug($this->Post->saveAll( $this->data, array('validate' => 'only')));
$this->Post->saveAll( $this->data, array('validate' => 'only') )


If I manually set data to the Category I get the messages saying too many
selected so the validation in Category is set correct.

I was just hoping saveAll would take care of this for me.

I can wite validation anywhere set it to any model but figured why should I
have to since all should be all :) Not some.

K
-Original Message-
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of euromark
Sent: Sunday, April 03, 2011 9:07 AM
To: CakePHP
Subject: Re: Validate HABTM Multiple

"but I never get any validation errors for the HABTM model "

what does $this->Post->saveAll() return?
boolean or array?

pr() it pretty quick - I had similar issues I think


On 1 Apr., 05:37, "Krissy Masters"  wrote:
> I can, but why should I have to validate the Category in the Post model?
>
> 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
>
> jeremybu...@classoutfit.comhttp://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
Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> athttp://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video
Tutorialshttp://tv.cakephp.org
> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> others with their CakePHP related questions.
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
athttp://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+unsubscr...@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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Validate HABTM Multiple

2011-04-03 Thread euromark
"but I never get any validation errors for the HABTM model "

what does $this->Post->saveAll() return?
boolean or array?

pr() it pretty quick - I had similar issues I think


On 1 Apr., 05:37, "Krissy Masters"  wrote:
> I can, but why should I have to validate the Category in the Post model?
>
> 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
>
> jeremybu...@classoutfit.comhttp://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 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> athttp://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video 
> Tutorialshttp://tv.cakephp.org
> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> others with their CakePHP related questions.
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


RE: Validate HABTM Multiple

2011-03-31 Thread Krissy Masters
I can, but why should I have to validate the Category in the Post model?

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

jeremybu...@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+unsubscr...@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+unsubscr...@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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Validate HABTM Multiple

2011-03-31 Thread Jeremy Burns | Class Outfit
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

jeremybu...@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+unsubscr...@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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Validate HABTM

2009-05-01 Thread red

Here you'll find the solution:
http://teknoid.wordpress.com/2008/10/16/how-to-validate-habtm-data/




On 1 Maj, 00:00, "Dave Maharaj :: WidePixels.com"
 wrote:
> I have tried figuring this out on my own to no avail.
>
> Where do I validate data being saved into a HABTM table? I have
> USERS:
> id
>
> SYSTEMS:
> id
> name
>
> USERS_SYSTEMS:
> id
> user_id
> system_id
>
> I created a simple form for the User to update their Systems but where is
> validation for this? Do I validate system_id in system model? Do I make a
> user_systems model and set a validation rule for system_id and user_id
> there? There is no system_id in the system model so it makes no sense to me
> to put it in there.  I made a user_systems model and put
> var $validate = array(
>   'system_id' => array('rule' => array('minLength', 8)) //min 8 just to
> check if it works as there are only single digit values in db
>  );
> but it still saves so I am at a loss
>
> Can someone point out what model do I use to validate the HABTM data being
> saved to the HABTM table?
>
> thanks
>
> Dave
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validate HABTM

2009-03-02 Thread Joel

I have the same problem.

It saves automatically but validation won't run.  To me it seems like
the logical place to put these validation rules is on the join table
in the HABTM relationship.  Ie PostsTag model, but unfortunately it
doesn't run.

It's weird that it will happily save the data, but it won't validate
by default.

On Mar 2, 6:01 pm, Günther Theilen  wrote:
> Hi,
>
> thank for the answer.
>
> I read the blog entry before but it didn't seem to be the most elegant
> way because in teknoid's example the Post model is only validated if 
> thevalidationof the Tag model was ok.
>
> With the other model associations I got thevalidationof both models
> working by calling saveAll().
> Isn't that possible withHABTM?
>
> Regards
> Guenther
>
> brian schrieb:
>
> > Have a look here
>
> >http://teknoid.wordpress.com/?s=validate+habtm
>
> > On Fri, Feb 27, 2009 at 9:30 AM, Günther Theilen  wrote:
> >> Hi,
>
> >> maybe I'm a bit dull but I can't figure out what I'm doing wrong here.
> >> Maybe someone can help:
>
> >> I've got two models: FooHABTMBar.
>
> >> In foo_controller, add method I do this:
>
> >> $bar = $this->Foo->Bar->find('list');
> >> $this->set(compact('bar));
>
> >> In the foo/add view I have:
> >> $form->input('Bar', array('multiple' => 'checkbox'))
>
> >> Which works as I expected.
>
> >> Now I want to validate the checkboxes.
>
> >> In models/bar.php I added
> >> var $validate = array('Bar' => array('rule' => 'testRule'));
>
> >> function testRule() {
> >>   debug ("test");
> >>   die();
> >> }
>
> >> In foo_controller, add method I tried this:
> >> $this->Foo->save($this->data)
> >> and this:
> >> $this->Foo->saveAll($this->data)
> >> and this:
> >> $this->Foo->saveAll($this->data, array('validate' => 'first'))
>
> >> All my othervalidationrules in the Foo-model work perfectly but the
> >> rule in Bar doesn't seem to be triggered.
>
> >> Where is my mistake?
> >> Any hints?
>
> >> Regards
> >> Guenther
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validate HABTM

2009-03-01 Thread Günther Theilen

Hi,

thank for the answer.

I read the blog entry before but it didn't seem to be the most elegant 
way because in teknoid's example the Post model is only validated if the 
validation of the Tag model was ok.

With the other model associations I got the validation of both models 
working by calling saveAll().
Isn't that possible with HABTM?

Regards
Guenther



brian schrieb:
> Have a look here
> 
> http://teknoid.wordpress.com/?s=validate+habtm
> 
> On Fri, Feb 27, 2009 at 9:30 AM, Günther Theilen  wrote:
>> Hi,
>>
>> maybe I'm a bit dull but I can't figure out what I'm doing wrong here.
>> Maybe someone can help:
>>
>> I've got two models: Foo HABTM Bar.
>>
>> In foo_controller, add method I do this:
>>
>> $bar = $this->Foo->Bar->find('list');
>> $this->set(compact('bar));
>>
>> In the foo/add view I have:
>> $form->input('Bar', array('multiple' => 'checkbox'))
>>
>> Which works as I expected.
>>
>> Now I want to validate the checkboxes.
>>
>> In models/bar.php I added
>> var $validate = array('Bar' => array('rule' => 'testRule'));
>>
>> function testRule() {
>>   debug ("test");
>>   die();
>> }
>>
>>
>> In foo_controller, add method I tried this:
>> $this->Foo->save($this->data)
>> and this:
>> $this->Foo->saveAll($this->data)
>> and this:
>> $this->Foo->saveAll($this->data, array('validate' => 'first'))
>>
>> All my other validation rules in the Foo-model work perfectly but the
>> rule in Bar doesn't seem to be triggered.
>>
>> Where is my mistake?
>> Any hints?
>>
>> Regards
>> Guenther
>>
>>
>>
>>
>>
> 
> > 


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validate HABTM

2009-02-27 Thread brian

Have a look here

http://teknoid.wordpress.com/?s=validate+habtm

On Fri, Feb 27, 2009 at 9:30 AM, Günther Theilen  wrote:
>
> Hi,
>
> maybe I'm a bit dull but I can't figure out what I'm doing wrong here.
> Maybe someone can help:
>
> I've got two models: Foo HABTM Bar.
>
> In foo_controller, add method I do this:
>
> $bar = $this->Foo->Bar->find('list');
> $this->set(compact('bar));
>
> In the foo/add view I have:
> $form->input('Bar', array('multiple' => 'checkbox'))
>
> Which works as I expected.
>
> Now I want to validate the checkboxes.
>
> In models/bar.php I added
> var $validate = array('Bar' => array('rule' => 'testRule'));
>
> function testRule() {
>   debug ("test");
>   die();
> }
>
>
> In foo_controller, add method I tried this:
> $this->Foo->save($this->data)
> and this:
> $this->Foo->saveAll($this->data)
> and this:
> $this->Foo->saveAll($this->data, array('validate' => 'first'))
>
> All my other validation rules in the Foo-model work perfectly but the
> rule in Bar doesn't seem to be triggered.
>
> Where is my mistake?
> Any hints?
>
> Regards
> Guenther
>
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---