objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.41k stars 304 forks source link

Support delete cascade #79

Open linheimx opened 7 years ago

linheimx commented 7 years ago

it's very helpful. greendao doesn't support it, hope it in here!

greenrobot commented 7 years ago

Can you specify what kind of cascade you are looking for? E.g. delete cascade?

linheimx commented 7 years ago

yes,delete cascade

greenrobot commented 7 years ago

Delete cascades is a dangerous thing to do, especially if you do this recursively. ("whoops where is my data??") Let's see.

bensandee commented 7 years ago

Reading through the docs on 1.0.1, a first step might be to clarify exactly what behaviors to expect when you delete while using ToOne and ToMany.

Maybe a brief blurb here, where you discuss removal of objects. http://objectbox.io/documentation/introduction/

Another place might be the javadocs of ToOne. Does getTargetId on an "orphaned" referent return an invalid value? No idea, honestly.

The typical behaviors would be set-to-null, throw exception or cascade delete I guess. I suppose this may be obvious to those expecting a NOSQL db, but coming from relational and realm I can't figure out the answer from current docs.

greenrobot commented 7 years ago

Thanks for the feedback. We will soon clarify that ToOnes are "nulled out" when the target entity is removed (target ID becomes 0).

vadimh77 commented 6 years ago

I propose to add an annotation for cascading delete that can be put on any possible relation in the entity.

For example:

class AEntity { @CascadeDeletion var bEntities : ToMany }

When i remove the AEntitiy then i expect that the bEntities will be removed too if no other AEntity that points on it anymore(ofcourse that you can leave this choice for the developer).

bryndsey commented 6 years ago

I agree with @vadimh77 - adding the ability to configure the behavior per relation seems like a good way to mitigate the aforementioned "whoops where is my data?" situation for most cases while still providing the functionality for the situations where cascading behavior makes sense. Google's Room library supports configuring the behavior ( https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.html )

meierjan commented 6 years ago

I agree with @blinz117 and @vadimh77. I am currently evaluating migrating a full project from Realm to objectbox. AFAIK in Realm cascading deletes are the default behavior. From my point of view think this is an essential feature. What's currently the best practice to do this?

Zhuinden commented 6 years ago

AFAIK in Realm cascading deletes are the default behavior.

It's really not, on deletion, links to the object are removed (item is removed from RealmLists, links to object become null), but there is no (publicly available and supported) way of marking a "parent-child" relationship in which "if the parent is removed, then so is the child".

The children have to be deleted manually, and then the parent manually. Which is technically manual cascade deletion.

It almost happened in https://github.com/realm/realm-java/pull/5678 :disappointed:

meierjan commented 6 years ago

Okay, I guess I had a misconception there - glad we talked about it :)

eduvm commented 5 years ago

For me the cascading delete is a essential feature.

Whithout this we broke the concept of removing a entire collection, cause i will need to iterate over every object to get his relation for manual delete

Zhuinden commented 5 years ago

JPA supports it and you can configure orphan removal and stuff.

tapanrgohil commented 5 years ago

please add this feature it will be so much use full

khandallalit commented 8 months ago

When tis is going to support this?