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 ?
To delete an object from a realmrealmRealm is an open source object database management system, initially for mobile operating systems (Android/iOS) but also available for platforms such as Xamarin, React Native, and others, including desktop applications (Windows), and is licensed under the Apache License.https://en.wikipedia.org › wiki › Realm_(database)Realm (database) - Wikipedia, pass the object to Realm. delete(_:) inside of a write transaction. // Previously, we've added a dog object to the realm.
To delete all objects from the realm, call Realm. deleteAll() inside of a write transaction.
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();
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With