Hi again,
I put the following in my Asset model :
function deleteAll($conditions, $cascade = true, $callbacks = true) {
$this->Behaviors->detach('Tree');
$return = parent::deleteAll($conditions, $cascade, $callbacks);
$this->Behaviors->attach('Tree');
return $return;
}
I placed a $this->log('Tree::beforeDelete was called for Asset.id ' .
$model->id) in beforeDelete callback in TreeBehavior. Even though I
detach TreeBehavior in Asset::deleteAll Tree::beforeDelete gets called
for every cascaded row delete. That's strange. Any ideas?
On 7 Jun., 19:21, biesbjerg <[EMAIL PROTECTED]> wrote:
> Hi grigri,
>
> thanks for your feedback.
>
> I get what you're saying, but is it just me or does it seem "wrong" to
> corrupt the tree, even though we fix it again (re-sync it)?
>
> On Jun 5, 5:09 pm, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Then the children will not get deleted and I'll end up with orphans..
>
> > Really? I admit I don't use the TreeBehavior, but I am familiar with
> > MPTT hierarchies, and I've got the code in front of me.
>
> > I might well be wrong, but it seems like this:
>
> > With the above code:
>
> > 1. You call Asset::del(<id>), maps to Model::del();
> > 2. Upload::beforeDelete() is called, file is deleted (<id>)
> > 3. Tree::beforeDelete() is called with <id>, Tree:deleteAll() is
> > called (once) for all descendants of <id> (not just direct children)
> > 4. Tree::deleteAll() detaches Tree behavior
> > 5. Tree::deleteAll() calls Model::deleteAll() with cascade and
> > callbacks
> > 6. Model::deleteAll() performs a find('all') - retrieving the ids of
> > all the descendants, calls Asset::del() on each descendant (maps to
> > Model::del())
> > 7. [each descendant] Model::del() calls Asset::beforeDelete, file is
> > deleted
> > (Tree::beforeDelete() is not called because it's still detached)
> > 8. Tree::deleteAll() re-attaches Tree behavior and exits
> > 9. Upload::beforeDelete re-syncs the tree
> > 10. rest of Asset::del(<id>)
>
> > I could be completely wrong here, but looking at the code it seems to
> > me this is how it would play out.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---