Open linheimx opened 7 years ago
Can you specify what kind of cascade you are looking for? E.g. delete cascade?
yes,delete cascade
Delete cascades is a dangerous thing to do, especially if you do this recursively. ("whoops where is my data??") Let's see.
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.
Thanks for the feedback. We will soon clarify that ToOnes are "nulled out" when the target entity is removed (target ID becomes 0).
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).
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 )
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?
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:
Okay, I guess I had a misconception there - glad we talked about it :)
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
JPA supports it and you can configure orphan removal and stuff.
please add this feature it will be so much use full
When tis is going to support this?
it's very helpful. greendao doesn't support it, hope it in here!