Deleting the parent record leaves orphan child records
I'm using IRRE for 1:n relations and m:n relations with an intermediate table. In both cases deleting the parent record leaves orphan child records. I have tried to fix this by adding foreign keys with ON DELETE CASCADE but after cat I couldn't create new records. An error message 2: SQL error: '' () appears on top of the page in a red box when I try. I guess IRRE tries to save the child record first, before the parent is created.
Having foreign keys would be really nice, but at least IRRE should also delete the child records when their parent is deleted. Until this gets fixed, is there a way I could use some hook to delete the child records manually as a workaround?
(issue imported from #M14233)
#1 Updated by Alexander Stehlik almost 8 years ago
- Target version deleted (
I had the same problem that Boros described.
I investigated a bit further and I think I found the problem:
When you look at t3lib_TCEmain::deleteRecord() you can see that when a delete row is configured (
$GLOBALS['TCA'][$table]['ctrl']['delete']) in the TCA the child records will be deleted by:
$this->deleteRecord_procFields($table, $uid, $undeleteRecord);
But when the records are directly deleted without setting a "deleted" flag or the
$forceHardDelete parameter is
TRUE this method (
deleteRecord_procFields) will never be called and the child records stay in the database.
I don't know if this is expected behaviour or if it is a bug. If it is expected, it would be great to get an explanation, why.