Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm: change field name for migration

I'd like to change field name in Realm DB migration process. It seems that changing field name is not supported, and only copy-and-remove is the only way to do.

is this correct? It consumes lots of time.

Below code is my trial to change field value to summary in copy-and-remove manner.

RealmSchema schema = realm.getSchema();
schema.get("Invoice")
.transform(new RealmObjectSchema.Function() {
    @Override
    public void apply(DynamicRealmObject obj) {
        obj.set("summary", obj.getString("value"));
    }
})
.removeField("value");
like image 448
Youngjae Avatar asked May 27 '16 18:05

Youngjae


1 Answers

Probably what you need is a method: renameField

Example:

RealmSchema schema = realm.getSchema();
schema.get("Invoice").renameField("value", "summary");
like image 94
PiKos Avatar answered Sep 23 '22 14:09

PiKos