Hi There

I think you are attempting this wrong.

If you set up your CakePHP Model Associations properly (User->Post->Liking)
then you don't need to find the various ID's to create your relationship.

Instead if your form includes things such as "User.somefield",
"Post.anotherfield", "Liking.anotherfield" and the 3 models are associated
together, when you save your data CakePHP will automatically insert records
in all of the tables (or update records) and it will automatically insert
the ID's into say "Post.user_id", "Liking.post_id"

I'm not entirely sure what data you are submitting but this may help you:

http://pastie.org/private/yn1jzdf59h1psflnkgsg


On 12 January 2011 08:57, Spha ps <[email protected]> wrote:

> function add() {
> if(!empty($this->data['User']['email'])) {
>
> if ($this->User->findByemail($this->data['User']['email']))
>  {
> //$this->set new post for the user with that email;
>   *$this->data['Post']['user_id'] =  $this->User->id;*
>  $this->User->Post->save($this->data);
> $this->data['Liking']['post_id'] = $this->User->Post->id;
>  $this->User->Post->Liking->save($this->data);
> $this->redirect(array('controller' => 'posts', 'action' => 'index'));
>  } else{
> //$this->set('error_msg', 'This Username is Available');
>  $user = $this->User->save($this->data);
>  // If the user was saved, Now we add this information to the data
>  // and save the Profile.
>
> if (!empty($user)) {
> // The ID of the newly created user has been set
>  // as $this->User->id.
> $this->data['Userinfo']['user_id'] = $this->User->id;
>
> // Because our User hasOne Profile, we can access
> // the Profile model through the User model:
>  $this->User->Userinfo->save($this->data);
> $this->data['Post']['user_id'] = $this->User->id;
>  $this->User->Post->save($this->data);
> $this->data['Liking']['post_id'] = $this->User->Post->id;
>  $this->User->Post->Liking->save($this->data);
>  $this->redirect(array('controller' => 'posts', 'action' => 'index'));
>  }
> }//end if ($this->User->findByemail($this->data['User']['email'])){
>  }//end if(!empty($this->data['User']['email'])) {
> }//end add
>



-- 
Kind Regards
 Stephen @ NinjaCoderMonkey

 www.ninjacodermonkey.co.uk

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