Delete child records

abc
sql
Tags: #<Tag:0x00007f60c6509898> #<Tag:0x00007f60c6508df8>

#1

I have a situation that gets me crazy.

I have standard Patent SQL table (isidentity ON) and related Child sql table - set relation On Delete: Restrict.

So I have standard Form for Parent table with a child record on it. When I Insert parent record it creates new ID so that can be used to insert Childs on the same form.

The problem is if I click Cancel it asks me a standard confirmation message like ‘Are you sure you want to cancel?’ (and I want to be asked), I say Yes and got Referential Integrity Delete Error like ‘This record is referenced from the file %File. This record cannot be deleted while these references exist.’ that is also correct.

BUT I need to get rid of the second message and delete related child records silently by myself.

How to achieve this, please? ABC, c10


#2

I might perhaps not be understanding the situation, but I would certainly make sure to define the child records as cascade delete in your SQL backend rather than depending upon ABC.


#3

Correct me if I’m wrong. But you want to insert a parent and children on a form. You want to just delete them if you press cancel during insert?
Have a look at Mike Hanson’s Super Invoice template. It keeps everything in memory before writing it out on ok.
I’ve also used a copy set of ‘edit’ tables where the parent and children get copied on edit or created on insert and on ok get copied back to the ‘real’ tables or just deleted on cancel. The advantage there is that a cancel will in fact cancel everything.
You might also be able to play with the transaction settings on those table to defer and enable a rollback to cancel.


#4

thank you guys, definitely, I will recheck my current workflow.


#5

I also use the method suggested by totalhip and let the SQL do it all. The ABC Templates work without any further modifications when you do it this way.
As a principle I generally let the SQL manage autoincrement and RI. That seems to sit well with the ABC chain…
I hope that helps, regards Jim