before/after delete - strange behavior
Posted 02 May 2009 - 03:15 PM
deleteAll() and deleteByPk() do the raw sql query, without any triggers.
Is it by design?
Actually, I want related records to be deleted when the main record is deleted.
I cannot do it by DB constraints (on delete cascade) because of some extra things that should be done before the record is deleted (for example, unlink some attached files, write data to log and so on).
Should I grab all related records and then call delete() on each of them? Or there's a better way?
PS. extra param in relation definition (like 'dependent' => true) that allows related records to be deleted automatically would be sooooo nice.. )))
Posted 03 May 2009 - 04:31 AM
Maybe a behavior would be a nice option so that developers can add this on demand? It could add two new "enhanced" methods (bad name suggestion: fullDeleteAll() and fullDeleteByPk()...) that fetch all records and call delete().
Posted 03 May 2009 - 04:42 AM
Should I really use two steps approach (findByPk() + delete())? Isn't it a little bit redundant?
Seems like I've missed something and there's much better way.
Posted 03 May 2009 - 04:50 AM
Maybe the easier approach for you would be to simply add a method like "deleteWithRelated()" and delete related records from there manually, before you delete the records in your main table.
Posted 06 December 2011 - 06:10 PM
It seems logic that you first need to load the record or otherwise attributes wont be available.
Searched quite a while before I found this topic on why afterDelete() was not called after calling deleteByPk()
I think this should be in the documentation/guide.
Posted 08 December 2011 - 12:03 AM