realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Migration .addField how to set a default boolean to true?

Open Paul776 opened this issue 10 years ago • 1 comments

class Account {
  isActive = true;
}

if (oldVersion == 3) {
        schema.get("Account")
            .addField("isActive", boolean.class);
        oldVersion++;
}

This is code for migrating my schema were I have added a isActive field that should be defaulted to true.

But after migration isActive is false. Is there a way to set the value to true by default ?

Paul776 avatar Nov 21 '16 18:11 Paul776

.transform(new RealmObjectSchema.Function() { @Override public void apply(DynamicRealmObject obj) { obj.set("isActive", true); } });

closed

Paul776 avatar Nov 21 '16 18:11 Paul776