42
Views
5
Comments
Solved
how to delete child recordĀ  associated with parent record ?
Question

Hi,

I am trying to make POC application.

requirement like i want delete parent record and child records also with associated.

example:- i have two entities State and city, state have multiple cities. so i now want delete state and cities which are associated with that sateId.

i tied with Delete Rule in Cities entity for the StateId reference attribute.

can you please suggest me.

2024-09-12 02-43-38
Deepsagar Dubey
Solution

Hi @kishore reddy 

In Delete rule there is one more thing to notice if your reference is in more then one entity and if you Opted Delete only for one and protect for another then it'll also give exception.

So better just create a action pass Id which you want to delete and use SQL statement to Delete all records by using where clause.

You can also maintain a flag Active or Inactive to avoid permanent data deletion. 

The solution which @Dorine Boudry mention will also work but for this u need to check all reference. 

I hope it'll also help you.

Thanks
Deep

UserImage.jpg
kishore reddy

Yes, it is working now. i did not noticed that cityID reference attribute using in another entity(Towns)  as refence key. i checked that and working fine. thank you 

2021-09-06 15-09-53
Dorine Boudry
Ā 
MVP
Solution

if your delete rule is set to option Delete, as you say, then deleting the state is all you need to do, the DBMS will take care of also deleting all cities referencing (being a child of) this state.

UserImage.jpg
kishore reddy

yes, i opted to Delete for StateId reference attribute. 

when i trying to Delete particular record getting Data base exception. operation not performing. pls suggest me

UserImage.jpg
kishore reddy
2024-09-12 02-43-38
Deepsagar Dubey
Solution

Hi @kishore reddy 

In Delete rule there is one more thing to notice if your reference is in more then one entity and if you Opted Delete only for one and protect for another then it'll also give exception.

So better just create a action pass Id which you want to delete and use SQL statement to Delete all records by using where clause.

You can also maintain a flag Active or Inactive to avoid permanent data deletion. 

The solution which @Dorine Boudry mention will also work but for this u need to check all reference. 

I hope it'll also help you.

Thanks
Deep

UserImage.jpg
kishore reddy

Yes, it is working now. i did not noticed that cityID reference attribute using in another entity(Towns)  as refence key. i checked that and working fine. thank you 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.