Thursday, June 3, 2010

Re: how to activate child afterDelete callbacks when i delete parent model?

The model call backs are only executed for the model being called and
not for the associated models that might also be effected by the call.
See the manual http://book.cakephp.org/view/76/Callback-Methods
"Please note that these callbacks are not called when dealing with
associated models; callbacks are only executed for the main model of a
query."

I would add a function to the Child model of cleanupImages().
Then in the Parent afterDelete iterate the children and call the
cleanupimages function.

afterDelete may be too late and you might need to deal with this in
the beforeDelete of the parent depending upon what info from the child
you need to properly clean up the images.


On Jun 2, 3:06 am, Kei Simone <kimc...@gmail.com> wrote:
> hi,
>
> i have a parent model that hasMany child models.
>
> when the child model is deleted, i need to delete the images
> associated with the child model.
>
> hence i want to place it in the afterDelete callback of the child
> model.
>
> now the association of parent with child is like this:
>
> var $hasMany = array(
>                 'Child' => array(
>                         'className' => 'Child',
>                         'foreignKey' => 'parent_id',
>                         'dependent' => true,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => true,
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 ),
>
>         );
>
> how do i activate the child afterDelete when i delete parent?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: