If I comment out other habtm relationships, leaving only var $hasAndBelongsToMany = array( 'HasAsFriend' => array( 'className' => 'User', 'joinTable' => 'friends', 'foreignKey' => 'user_id', 'associationForeignKey' => 'friend_id', 'uniq' => false, 'conditions' => '', ), ); in my User model, then the save() will go flawlessly.
However, if I leave those relationships in User model, then the data is inserted into other tables even if I manually unbindModel() them before calling $this->User->save(). I'm confused. Is there anyone who knows why this is happening? Or maybe I should just use a $this->User->query() to do the saving job and insert the data in the right table? :( On 5月8日, 上午6時13分, largon <[EMAIL PROTECTED]> wrote: > Hi, > > I'm on a project that users can add other users as friends, families, > or block them. > So I've set up some habtm behaviors for that. The tables (friends, > families, blocks) look > very similar, all with (user_id, friend_id) or (user_id, family_id) as > keys. > > But when I save a data, like calling: > $this->data['User']['id'] = 1; > $this->data['HasAsFriend']['HasAsFriend'] = 2; > $this->User->save($this->data); > > I'll have not only user1 adding user2 as friend, but also user2 adding > user1 as friend. > What's more, they're each other's families and user1 is blocking user2 > too. > (The data got inserted into families table and blocks table too.) > > I posted my user model relationships athttp://bin.cakephp.org/view/241705085 > I also tried the behavior > athttp://bakery.cakephp.org/articles/view/add-delete-habtm-behavior > , > but with the code: > > $this->User->habtmAdd('HasAsFriend', 1, 2); > > Also results the same as inserting into families table and blocks > table. > > I'm troubled, I'm not sure why this is happening. Any clues is greatly > appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---