realmList.deleteAllFromRealm not working

1.2k views Asked by At

I have parent realm object like this:

public class Parentdb extends RealmObject {
     @PrimaryKey
     public long id;

     RealmList<Child> childs;
}

and I want to remove all child's from parent for that I use this code:

realm.beginTransaction();
parentdb.childs.deleteAllFromRealm();
realm.commitTransaction();

Child child=realm.where(Child.class).findFirst();      

after run this code child must be null right?
but it's not!!!
am I doing something wrong?

1

There are 1 answers

0
EpicPandaForce On
realm.beginTransaction();
parentdb = realm.where(Parentdb.class).equalTo("id", 1L).findFirst();
parentdb.childs.deleteAllFromRealm();
realm.commitTransaction();

parentdb = realm.where(Parentdb.class).equalTo("id", 1L).findFirst();
assertThat(parentdb.childs.size()).isEqualTo(0); // should be true

Basically you have more children in the database than just what belongs to that single parentDb object.