问题
I have a big object that has a lot of relationships with other objects and those objects have relationships with other objects as well. So when i delete the root object, i found out that only the parent object is being deleted while all its relationships are not, is there way to delete the whole tree in the same transaction ?
回答1:
Realm doesn't support cascading delete
for now. You can vote for that feature there. In the current case, seems you need to do it manually, one by one.
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RootObj root = realm.where(RootObj.class)
.equalTo(RootObjFields.ID, rootId)
.findFirst();
if(root != null) {
if(root.getChild() != null) {
root.getChild().deleteFromRealm();
}
root.deleteFromRealm();
}
}
});
来源:https://stackoverflow.com/questions/40426414/how-to-delete-realm-objects-with-their-child-relations