realm-java
realm-java copied to clipboard
ArrayIndexOutOfBoundsException in migration script using removeFromRealm()
Hi,
I'm trying to clear an entire table's data after version upgrade in my migration script using following snippet but getting ArrayIndexOutOfBoundsException.
RealmObjectSchema personSchema = schema.get("Person");
personSchema.transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject dynamicRealmObject) {
if (!dynamicRealmObject.getBoolean("active")) {
dynamicRealmObject.removeFromRealm();
}
}
});
Is there another way to clear up only one table, or clear records based on some check other than using removeFromRealm() in migration script?
Sorry, but now you cannot remove object in the transform function.
You can do this in the migration block instead:
RealmResults<DynamicRealmObject> results = realm.where(`Person`).equalTo("active", false).findAll();
results.clear();
We will add java doc for this.
Thanks. That's helpful.