Realm-java: Cascade Deletes or Deleting RealmList Items from RealmObject

Created on 3 Aug 2015  Â·  19Comments  Â·  Source: realm/realm-java

I have a case where I'm calling a copyToRealmOrUpdate(List) and I have noticed that the RealmList that is a property on MyObject gets updated to the new list for MyObject but old objects get orphaned and not deleted. My guess is that there is no support for cascading deletes. Since they don't have primary keys, I have no identifiable way to query them and remove them after the fact.

What would be the best possible solution for this? Would MyObject's property need to also have MyObject's primary key in order to query and delete those old orphaned objects? I could try some sort of app processing to remove them before the copyToRealmOrUpdate but it seems really heavy and only grows as the number of MyObjects grows.

Get a List
For each MyObject, query for the stored Realm MyObject.
Get RealmList from stored Realm MyObject
Loop through RealmList object and removeFromRealm

Thoughts?

T-Help

All 19 comments

Hi @maarek Sorry for the late response.
Yeah, unfortunately cascading deletes are not supported yet. You can follow progress on that here https://github.com/realm/realm-java/issues/1104

Right now your only option is something like what you outlined.

Are you planning to support cascade delete? If so what is the priority?

Yes, we are planning to support cascading deletes. It is currently under study in the core team.

+1

Was there a verdict on this? Saw that it got closed without any update on the support of cascading deletes? :)

@maarek I closed it as #1104 is the issue to follow instead.

+1 On this issue

+1 please

bump

@badjano this is duplicate of https://github.com/realm/realm-java/issues/1104

+1

Good job Realm Team. I think it's a great db.
Obviously needs more work for some features like cascade deletions but we can develop some object methods for that.
Thanks
+1

Any update on cascade delete?

Sync doesn't support it so ObjectStore doesn't implement it so Java is stuck in limbo.

https://github.com/realm/realm-java/pull/5678

Well, isn't that dangerous ? Realm is a graph database and links between objects can quickly get out of hand and it would be easy to CASCADE DELETE all the graph by the sole "spaghetti effect".

Please reopen, this was never solved.

It is a duplicate of #1104

5 years later?

@asymptotik They are quite quick 🤣

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuwu picture yuwu  Â·  3Comments

bryanspano picture bryanspano  Â·  3Comments

iAbdulaziz picture iAbdulaziz  Â·  3Comments

Merlin1993 picture Merlin1993  Â·  3Comments

wezley98 picture wezley98  Â·  3Comments