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

2010-06-03 Thread LunarDraco
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


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

2010-06-03 Thread cricket
On Jun 3, 1:26 pm, LunarDraco mdc...@gmail.com wrote:

 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.

To add to that, you'll likely need to know the ID of the parent model
in order to remove the correct records and files for the child model.
So pass the ID off to the other model. Something like:

function afterDelete()
{
$this-ChildModel-cleanupImages($this-id);
}

$this-id is set in Model::delete() before the record is removed. It's
then set to false after the afterDelete callback.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


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

2010-06-02 Thread Kei Simone
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en