Wednesday, September 7, 2011

Re: Delete translated contents for a Tree Model

Hi there,

I've made this in the model which uses the Tree and Translate
behaviors:

// Add a private var in the model, to store children of record to
delete
private $translated_children = array();

// Add callbacks to store children and delete it
public function beforeDelete() {
$children = $this->children($this->id,false,array('id'));
if (!empty($children)) {
$this->translated_children = Set::extract('/MyModelName/id',
$children);
}
return true;
}

public function afterDelete() {
if (!empty($this->translated_children)) {
$translateModel = $this->translateModel();
$translateModel->deleteAll(array('model'=>$this-
>alias,'foreign_key'=>$this->translated_children));
}
return true;
}

Maybe we can extends core TranslateBehavior and pass a parameter to
tell the model use TreeBehavior to make this trick.

Avairet

On 1 sep, 17:09, avairet <avai...@cakephp-fr.org> wrote:
> I'm using TranslateBehavior on a model that is a Tree Model.
>
> When I delete a child node from the Tree, related contents in my i18n
> table are correctly deleted.
> But if I delete a parent node, only related contents for this parent
> node are deleted from the i18n table, translated contents for the
> child nodes are not deleted.
>
> I see that in the afterDelete() method of TranslateBehavior, a
> deleteAll() call is executed, but it take only the current id and it
> didn't make a cascading delete.
>
> Have you an idea to improve that?
>
> Hope my question is clear...
>
> Avairet

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: