Friday, November 28, 2008

Re: CakePHP Revision 7896: HABTM Issue (deleting one relation deletes other relations)

I filed a ticket for this.

On Nov 29, 12:32 am, Marcus Silva <marcuslighten...@gmail.com> wrote:
> Had exactly the same problem :http://groups.google.com/group/cake-php/
> browse_thread/thread/64516dd7a1b63d0c/f350fa78c7cfc772?
> hl=en&lnk=gst&q=an+easy+way+to+add+roles#f350fa78c7cfc772
>
> nobody has replied to my post. Very sad....
>
> It must be a bug for sure, I ended up writting my on function to add
> and delete the role of a user.
>
> Hopefully somebody will know what is going wrong.
>
> On Nov 28, 3:51 pm, Milmar <milmarq...@gmail.com> wrote:
>
> > 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.
>
> > Is anybody else seeing this issue? (I made a search and didn't see any
> > ticket concerning this).
> > Or am I just confused and this is actually the correct behavior for
> > the delete function?
>
> > Thanks.
--~--~---------~--~----~------------~-------~--~----~
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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: