The original is:

function add()
{
    if (!empty($this->data))
    {
        //We can save the Post data:
        //it should be in $this->data['Post']

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

        //Now, we'll need to save the Comment data
        //But first, we need to know the ID for the
        //Post we just saved...

        $post_id = $this->Post->getLastInsertId();

        //Now we add this information to the save data
        //and save the comment.

        $this->data['Comment']['post_id'] = $post_id;

        //Because our Post hasMany Comments, we can access
        //the Comment model through the Post model:

        $this->Post->Comment->save($this->data);

    }
}

On Jan 28, 7:43 pm, Raistlin Majere <[EMAIL PROTECTED]> wrote:
> function add()
> {
>     if (!empty($this->data))
>     {
>         // Here we save all post data.
>         // If Comment is part of all post data, we save Comment.
>
>         $this->Post->save($this->data);
>
>         $post_id = $this->Post->getLastInsertId();
>
>         $this->data['Comment']['post_id'] = $post_id;
>
>         // Observe that Comment is part of Post.
>         // Observe that Comment was saved and Comment is saved again.
>
>         $this->Post->Comment->save($this->data);
>
>     }
>
> }
>
> // Why save the Comment data twice?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to