Search code examples
axaptadynamics-ax-2009cascading-deletes

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().


Solution

  • 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.