Page 1 of 1

How to delete children records?

PostPosted: Thu Apr 11, 2019 6:42 pm
by pbdavis
I have a form with relationships. I need the ability to selectively delete the children. I get the child in a record I want to delete. But the deleteRecord(rec) deletes all the children and the parent record in another table.
Code: Select all
function onAction(event) {
   // Delete selected image record.
   var rec = forms.frm_MOD_fsr_image_pict_Edit.foundset.getRecord(1);
   application.output("Rec id = " + rec.fsr_image_id);

Can someone tell me why this is deleting Parent and children? And how to delete just the selected child?

Re: How to delete children records?

PostPosted: Thu Apr 11, 2019 7:55 pm
by mboegem
Hi Paul,

Just a wild guess, since I don't know what your solution looks like.
I think you have to relations in your solution:
1) child_to_parent
2) parent_to_children

If this is the case most likely both relations have the 'delete related record' checkbox ticked.
I can imagine this should be the case for the 2nd relation, but definitely not for the first one.

Hope this helps.

Re: How to delete children records?

PostPosted: Thu Apr 11, 2019 8:50 pm
by pbdavis
Awesome Marc! That was it. There was a child_to_parent relation with 'Delete related record' checked.
Thanks some much. This one had me stumped.

Re: How to delete children records?

PostPosted: Wed Jan 15, 2020 12:06 am
by Bernd.N
Hi Paul,
although it has been a while since your thread:
When detecting such an issue, you might want to check all relations regarding the "Delete related record" checkbox.

A complete overview of such settings in a table view of all relations would be handy for such a purpose, though I do not know if that is possible somehow.

So far I did not see any example where a parent should get killed when a child has to be deleted.
As this should be very seldom, maybe it would be an idea for the Servoy system to ask "Are you sure to delete the parent as well?" when someone accidently checks that box in a child-to-parent-relation.