#5819: CakePHP Revision 7896: HABTM Issue (deleting one relation deletes other
relations)
-------------------------------+--------------------------------------------
    Reporter:  milmarqtan      |          Type:  Bug     
      Status:  new             |      Priority:  Critical
   Milestone:  1.2.x.x         |     Component:  Model   
     Version:  RC3             |      Severity:  Critical
    Keywords:  HABTM Delete    |   Php_version:  PHP 5   
Cake_version:  1.2.0.7692 RC3  |  
-------------------------------+--------------------------------------------
 This issue might be related to ticket #5579 which was fixed in
 revision 7795. I was seeing the same issue as #5579 for the edit and
 save functions but I verified that it is already fixed in revision
 7795 and later (I'm currently using revision 7896).

 Now, my problem is with the delete function, and it's quite easy to
 reproduce.

 For example, you have three tables, namely, "roles", "users", and
 "roles_users" (where "roles_users" is the join table).

 After baking, the role model is defined as:


 {{{



 <?php
 class Role extends AppModel {

         var $name = 'Role';

         //The Associations below have been created with all possible keys,
 those that are not needed can be removed
         var $hasAndBelongsToMany = array(
                         'User' => array('className' => 'User',
                                                 'joinTable' =>
 'roles_users',
                                                 'foreignKey' => 'role_id',
                                                 'associationForeignKey' =>
 'user_id',
                                                 'unique' => true,
                                                 'conditions' => '',
                                                 'fields' => '',
                                                 'order' => '',
                                                 'limit' => '',
                                                 'offset' => '',
                                                 'finderQuery' => '',
                                                 'deleteQuery' => '',
                                                 'insertQuery' => ''
                         )
         );

 }

 ?>
 }}}

 ...and the user model is defined as:


 {{{
 <?php
 class User extends AppModel {

         var $name = 'User';

         //The Associations below have been created with all possible keys,
 those that are not needed can be removed
         var $hasAndBelongsToMany = array(
                         'Role' => array('className' => 'Role',
                                                 'joinTable' =>
 'roles_users',
                                                 'foreignKey' => 'user_id',
                                                 'associationForeignKey' =>
 'role_id',
                                                 'unique' => true,
                                                 'conditions' => '',
                                                 'fields' => '',
                                                 'order' => '',
                                                 'limit' => '',
                                                 'offset' => '',
                                                 'finderQuery' => '',
                                                 'deleteQuery' => '',
                                                 'insertQuery' => ''
                         )
         );

 }

 ?>
 }}}

 The role and user controllers just use a simple scaffold (although the
 issue could still be reproduced even if you're not using a scaffold).

 Supposing you have the following data and relations:
 User - User A, User B
 Role - Role A, Role B, Role C

 Join table:
 User A <-> Role A
 User A <-> Role B
 User A <-> Role C
 User B <-> Role B

 Issue: If you delete User A, ALL relationships (including that of User
 B and Role B) are deleted from the join table. If you delete User B,
 the relationship between User B and Role B will be deleted AND the
 relationship between User A and Role B will ALSO be deleted.

 My expected behavior: If you delete User A, only the relationships for
 User A would be deleted from the join table. The relationship for User
 B should remain. If you delete User B, only the relationship for User
 B will be deleted, all relationships for User A should remain.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5819>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to