Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use 1:n DeleteActions

How is it possible to use DeleteActions for 1:n table-relations?

Example:

Table A ("id")
('foo')
,('bar')
,('blup')

Table B: ("id", "tableAId1", "tableAId2")
(1, 'foo', 'blup')
,(2, 'bar', 'foo')

I have two relations on tableB:

TableB:tableAId1 -> TableA:id
TableB:tableAId2 -> TableA:id

Both datasets in table B should be deleted, if 'foo' from table A is deleted.

I tried one delete-Action on table A, refering to table B with cascade-option, resulting in only dataset 1 in table B was deleted.

I tried two identical delete-Action on table A, refering to table B with cascade-option, resulting in table lock on database.

I know about overwriting delete() method on table A, but this isn't safe if using tableA.doDelete().

like image 372
Nico Avatar asked Jan 21 '26 04:01

Nico


1 Answers

In AX 2009 and previous a delete action on a table only follows one of the relations (the first alphabetically sorted). A table should only be applied as a delete action once.

Your best choice then is to do your own cascade delete using delete_from in the delete method of your master table. If you do a doDelete, it will not delete the child records. Then just don't use the doDelete method!

In AX 2012 you explicitly specify which relation to follow on a delete action. You can apply the same table more than once, provided you specify different relations.

This is a nice feature, but is one of the reasons that table relations on the extended data types had to die.

like image 176
Jan B. Kjeldsen Avatar answered Jan 26 '26 00:01

Jan B. Kjeldsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!