Hi ,
If the model associations are correct and the for is created using User
just user
$this->User->saveAll($this->data,array('validation'=>'first'))
will validate all the Models, well as I said the model associations must be
perfect.
Regards
Sijo Jose C
On Wed, Dec 24, 2008 at 4:25 PM, Nature Lover
<[email protected]>wrote:
>
> Hi!
>
> I am new to CakePHP and currently working on an e-commerce site having
> three models:
>
> User( id, name, joined)
> UserProfile( id, user_id, title, age, email )
> UserContacts( id, user_id, name, address)
>
> Currently receiving data from a form as below:
>
> $this->data['User']['name']
> $this->data['UserProfile']['title']
> $this->data['UserProfile']['age']
> $this->data['UserProfile']['email']
> $this->data['UserContact']['0']['name']
> $this->data['UserContact']['0']['address']
> $this->data['UserContact']['1']['name']
> $this->data['UserContact']['1']['address']
>
> tried to validate data in User controller as:
>
> $this->User->set($this->data);
> $this->User->UserProfile->set($this->data);
> $this->User->UserContact->set($this->data);
>
> if($this->User->validates())
> {
> if($this->User->UserProfile->validates())
> {
> if($this->User->UserContact->validates())
> {
> $this->set('status','valid');
> }
> }
> }
> else
> { $this->set('status','invalid'); }
>
> Here proper validation fails for UserContacts although showing errors
> as
> $this->validationErrors['UserContact']['fieldname']
> instead of
> $this->validationErrors['UserContact']['0']['fieldname'] and
> $this->validationErrors['UserContact']['1']['fieldname']
>
> Also tried to use saveAll with validate=only, but failed due to
> foreign key constrains as getting error:
>
> 'This field cannot be left blank'
> for
> $this->validationErrors['UserProfile']['user_id'] and
> $this->validationErrors['UserContact']['0']['user_id']
> $this->validationErrors['UserContact']['1']['user_id']
>
> Please help me to get out of this hurdle.
>
> Thanks!
> >
>
--
Sijo Jose Chakramakkil
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---