For anybody who's following this thread, or had the same problem, or dived in during a google:
This seems like a bug mentioned at https://trac.cakephp.org/ticket/4558 After adding a unset($newValues) as the ticket mentions the problem goes away. Thanks all! On May 8, 5:08 pm, largon <[EMAIL PROTECTED]> wrote: > I added some logging just to make sure the relationships are unbound: > > $this->User->unbindAll(array('hasAndBelongsToMany' => > array('HasAsFriend'))); > $this->log("current habtm: " . print_r($this->User- > > >hasAndBelongsToMany, true)); > > The error log reads: > > 2008-05-08 17:03:49 Error: current habtm: Array > ( > [HasAsFriend] => Array > ( > [className] => User > [joinTable] => friends > [foreignKey] => user_id > [associationForeignKey] => friend_id > [uniq] => > [conditions] => > [with] => Friend > [fields] => > [order] => > [limit] => > [offset] => > [unique] => 1 > [finderQuery] => > [deleteQuery] => > [insertQuery] => > ) > > ) > > Which indicates that those relationships are unbound successfully. > But the habtmAdd still inserts into other tables: > > $this->User->habtmAdd('HasAsFriend', 1, 3); > > will result with SQL queries: > > 28 INSERT INTO `friends` (`user_id`,`friend_id`) VALUES (1,3) > 29 SELECT `Friend`.`id` FROM `friends` AS `Friend` WHERE `friend_id` = > 1 > 30 INSERT INTO `friends` (`friend_id`,`user_id`) VALUES (1,3) > 31 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `user_id` = > 1 > 32 INSERT INTO `families` (`user_id`,`family_id`) VALUES (1,3) > 33 SELECT `Family`.`id` FROM `families` AS `Family` WHERE `family_id` > = 1 > 34 INSERT INTO `families` (`family_id`,`user_id`) VALUES (1,3) > 35 SELECT `Block`.`id` FROM `blocks` AS `Block` WHERE `user_id` = 1 > 36 INSERT INTO `blocks` (`user_id`,`block_id`) VALUES (1,3) > > This is wierd. Is this a bug in cake or is it my misconfiguration in > User model? > > On 5月8日, 下午4時41分, largon <[EMAIL PROTECTED]> wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---