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 [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?hl=en
-~----------~----~----~----~------~----~------~--~---