RE: Proper way to validate related models?

2009-10-06 Thread Dave Maharaj :: WidePixels.com

 Yeah thanks,

Not going to bother with it I think.

Since what I have works now I will just stick with it.

dave

-Original Message-
From: Miles J [mailto:mileswjohn...@gmail.com] 
Sent: October-06-09 11:36 PM
To: CakePHP
Subject: Re: Proper way to validate related models?


$options = array('validate' => 'first', 'fieldList' => array());

Im not sure you it would be structured, you can of course just try and add
multiple models to the field list.

On Oct 6, 6:03 pm, "Dave Maharaj :: WidePixels.com"
 wrote:
> I read the saveAll in the bookand it says define $fieldList but 
> looking at the saveAll it
>
> fieldList: Equivalent to the $fieldList parameter in Model::save()
>
> saveAll(array $data = null, array $options = array())
>
> Where do youput the $fieldlist array and how is it structured? Per 
> model User => array('name', 'age') or all in one array('User.name',
> 'Profile.color')
>
> Thanks,
>
> Dave
>
> -Original Message-
> From: Miles J [mailto:mileswjohn...@gmail.com]
> Sent: October-06-09 9:32 PM
> To: CakePHP
> Subject: Re: Proper way to validate related models?
>
> Or you can use saveAll() and pass and option of validate = first.
>
> http://book.cakephp.org/view/75/Saving-Your-Data


--~--~-~--~~~---~--~~
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: Proper way to validate related models?

2009-10-06 Thread Miles J

$options = array('validate' => 'first', 'fieldList' => array());

Im not sure you it would be structured, you can of course just try and
add multiple models to the field list.

On Oct 6, 6:03 pm, "Dave Maharaj :: WidePixels.com"
 wrote:
> I read the saveAll in the bookand it says define $fieldList but looking at
> the saveAll it
>
> fieldList: Equivalent to the $fieldList parameter in Model::save()
>
> saveAll(array $data = null, array $options = array())
>
> Where do youput the $fieldlist array and how is it structured? Per model
> User => array('name', 'age') or all in one array('User.name',
> 'Profile.color')
>
> Thanks,
>
> Dave
>
> -Original Message-
> From: Miles J [mailto:mileswjohn...@gmail.com]
> Sent: October-06-09 9:32 PM
> To: CakePHP
> Subject: Re: Proper way to validate related models?
>
> Or you can use saveAll() and pass and option of validate = first.
>
> http://book.cakephp.org/view/75/Saving-Your-Data
--~--~-~--~~~---~--~~
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: Proper way to validate related models?

2009-10-06 Thread Dave Maharaj :: WidePixels.com

I read the saveAll in the bookand it says define $fieldList but looking at
the saveAll it

fieldList: Equivalent to the $fieldList parameter in Model::save()

saveAll(array $data = null, array $options = array()) 

Where do youput the $fieldlist array and how is it structured? Per model
User => array('name', 'age') or all in one array('User.name',
'Profile.color')

Thanks,

Dave

-Original Message-
From: Miles J [mailto:mileswjohn...@gmail.com] 
Sent: October-06-09 9:32 PM
To: CakePHP
Subject: Re: Proper way to validate related models?


Or you can use saveAll() and pass and option of validate = first.

http://book.cakephp.org/view/75/Saving-Your-Data


--~--~-~--~~~---~--~~
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: Proper way to validate related models?

2009-10-06 Thread Miles J

Or you can use saveAll() and pass and option of validate = first.

http://book.cakephp.org/view/75/Saving-Your-Data
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Proper way to validate related models?

2009-10-06 Thread Dave Maharaj :: WidePixels.com

In most of my case I am saving data for two or more related models but not
sure if I am going about it the right way.

 
I am using save() for each related model because I want to specify what
fields can have data saved to them (using AJAX so I know about Security
component and it wont work)
Example if in the User controller save();

If I use saveAll there is no way for me to specify what fields per model I
am allowing data to be saved is there?

$white = array('id', 'firstname', 'lastname', 'password', 'username');
if ($this->User->save($this->data, true,
array_intersect(array_keys($this->User->schema()), $white))) {
 
$this->data['Model1']['id'] = $this->User->id;
$model_1 = array('field_1','field_2');
$this->User->ModelOne->save($this->data, true,
array_intersect(array_keys($this->User->ModelOne->schema()), $model_1));

$this->data['Addition']['id'] = $this->User->id;
$model_2 = array('field_1','field_2','field_3');
$this->User->ModelTwo->save($this->data, true,
array_intersect(array_keys($this->User->ModelTwo->schema()), $model_2));


$this->data['Model3']['id'] = $this->User->id;
$model_3 = array('field_1','field_2','field_3');
$this->User->ModelThree->save($this->data, true,
array_diff(array_keys($this->User->ModelThree->schema()), $model_3));

And when saving to the related data, true means validate them but is there a
way to unbind validation from a related model?
I know I can call it from in the controller Users like:

$this->User->unbindValidation('keep', array('id', 'lastname', 'username',
'email', 'password', 'confirm', 'slug'), true);

But do all validation methods run whenever model data is saved or just the
fields being saved? I mean if I am only saving 'age' and 'location' in
User->Profile model, yet there are 10 other validation rules all set
required in the User->Profile Model will validation fail even if the 2 im am
trying to save validate?

 
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
-~--~~~~--~~--~--~---