Tuesday, February 23, 2010

Re: problem updating multiple related table record using save

Make sure the child models have their id setted.
CakePHP adds a new record if the id is empty.

On 23 fev, 10:59, John <johnmeh...@gmail.com> wrote:
> I have user's profile split into 3 tables)one parent table linked to
> two child tables(with foreign keys set to id of parent table and both
> with cascade option set on delete and update). Parent table relate to
> one record on the two child tables.
>
> I have declared $hasmany on main table model
> ( $hasMany=array('child1', 'child2')) and &belongs to parent table on
> child models. I tried to declare $hasone=array('child1', 'child2)' on
> the parent model; but showed error.
>
> My problem is when i try to edit and save a profile, a new record ia
> added in the child tables instead of updating the existing record. I
> tried using update, updateAll, save, saveAll. but nothing is working.
>
> Please correct me where i went wrong. The following is my edit profile
> code.
>
> function profile(){
>         if (empty($this->data)) {
>             $this->data = $this->Ulog->read();
>             } else {
>                 if ($this->Ulog->saveAll($this->data)) {
>                     $this->Session->setFlash('Your post has been
> updated.');
>                     $this->render('index');
>                     }
>                 }
>             }
>
> Thankx
> John M

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

No comments: