Cascading Delete
Cascading Delete
It would be great if AppGini had the ability to cascade delete all children records when a parent record is deleted. Just a thought.
Re: Cascading Delete
Hmmm, should work.
Can you check the following settings:
PS: Another idea is creating a trigger on database level, but, personally, I prefer not creating database triggers for better (=easier) portability/migration/updates.
Can you check the following settings:
- Grant DELETE-permission on the subtables for the user's group who is deleting the master record
- Check the correct setup of the lookups (as those connect a subtable's records to a master record)
- Option
[x] Delete records even if they have children records
- Option
[X] Allow mass delete
on the master table - Just for clarification: Check the PHP function
TABLENAME_delete()
inTABLENAME_dml.php
. All related subtables should have a separate block of code, starting with// child table: SUBTABLENAME
. If your code does not delete related records of certain tables, check if those tables do have a separate code-block there. If not, I guess there is a problem with setup of that specific lookup.
_before_delete()
-hook. After deleting all child-records manually you should also cleanup orphanened membership_userrecords
.PS: Another idea is creating a trigger on database level, but, personally, I prefer not creating database triggers for better (=easier) portability/migration/updates.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 23.16 Revision 1515 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 23.16 Revision 1515 + all AppGini Helper tools
Re: Cascading Delete
Hi Jan,
I have done the items you suggest and am able to delete the parent record but then I still have orphaned children records.
I have done the items you suggest and am able to delete the parent record but then I still have orphaned children records.
Re: Cascading Delete
Hi Jan,
How do I write that query to delete child records in the before delete hook? I have things set the way you describe in your post, however I still get orphaned records whenever the parent record is deleted.
Ray
How do I write that query to delete child records in the before delete hook? I have things set the way you describe in your post, however I still get orphaned records whenever the parent record is deleted.
Ray
Re: Cascading Delete
As starting point:
Given two tables
in
PS: You should cleanup
Given two tables
A
, B
with B.a_id = A.id
in
A_after_delete
-hook you should get primary key of deleted record in $selectedID
variable. Code: Select all
$cmd = "DELETE FROM B WHERE B.a_id = '{$selectedID}'";
$eo = [];
sql($cmd, $eo);
membership_userrecords
, too.Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 23.16 Revision 1515 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 23.16 Revision 1515 + all AppGini Helper tools