How to delete children records?

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

How to delete children records?

Postby pbdavis » Thu Apr 11, 2019 6:42 pm

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);
   forms.frm_MOD_fsr_image_pict_Edit.foundset.deleteRecord(rec);
}


Can someone tell me why this is deleting Parent and children? And how to delete just the selected child?
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

Re: How to delete children records?

Postby mboegem » Thu Apr 11, 2019 7:55 pm

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.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: How to delete children records?

Postby pbdavis » Thu Apr 11, 2019 8:50 pm

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.
~Paul
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

Re: How to delete children records?

Postby Bernd.N » Wed Jan 15, 2020 12:06 am

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.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests