Sunday, August 30, 2009

Re: Dependent=true, too much data is deleted

This might be the same problem I had when migrating to 1.2 last year.
The conditions in all associations MUST be arrays or you will get
these kinds of strange problems.

so try: array('Comment.parent_type'=>'event')

/Martin


On Aug 30, 8:06 am, Jeroen <jdenh...@inflate.nl> wrote:
> Hi all,
>
> Nasty problem: I have model Event and model Post, and both are
> associated with model Comment through a hasMany association. I've also
> set dependent = true:
>
>                 var $hasMany = array(
>                         'Comment' => array(
>                                 'foreignKey' => 'parent_id',
>                                 'conditions' => "Comment.parent_type = 'event'",
>                                 'order' => "Comment.id ASC",
>                                 'dependent' => true
>                         );
>
> Now, when I delete Event with id 28, all comments with parent_id 28
> will be deleted, also the ones that belong to Post.
>
> I guess I know why this happens (dependent only uses the parent_id to
> determine the comments to be deleted, not the extra conditions), but
> might there be a way of dealing with this other than defining a
> comments model for every other model that needs it?
>
> Thanks,
>
> Jeroen
--~--~---------~--~----~------------~-------~--~----~
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: