Delete rules problem

Delete rules problem

I have an entity diagram with entities:

O2 and O3 (both refers back to O1)
O4 (refers to O2 and O3)

I would like to have the delete rules such that if O1 is deleted, then O2 and O3 are also deleted -
and if either O2 or O3 is deleted, then O4 is deleted.

However, this does not seem to be possible. Service Studio keeps complaining about loops, etc. when I do this. How can I handle it?

Hi Claus,

Can you attach a screenshot showing those errors from Service Studio?
I have removed the delete rule between O1 and O2. If I leave it in, I get the error message below:

Unable to upgrade database schema. Error trying to create foreign key on database field 'OSUSR_r0d_O2.O1ID'.
Exception: Introducing FOREIGN KEY constraint 'OSFRK_OSUSR_r0d_O2_OSUSR_R0D_O1_O1ID' on table 'OSUSR_R0D_O2' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.

I can't share any more than this because the project is confidential, unfortunately...
I've also replaced the real object names with O1 and O2 in the above.
So this is an issue from the database. This problem would happen either if you're using the OutSystems Platform or any other language/platform that relies on a relational database engine.
The problem is that you have two foreign keys in the same entity (O4) with the delete rule that can be cascade deleted from another entity (O1). This creates multiple cascade paths and the database doesn't support that.
My suggestion is that you change one of the foreign key rules in O4 to ignore. This means that when you delete O1 you will delete all O2, O3 and O4. If you delete O2 you will delete all O4. The missing case is when you delete O3 you have to programmatically delete O4 defore you delete O3 and for that you can create a user action to do it.