React Native Realm Migration: Proper way to set value of a property in migration

55 views Asked by At

Hi I am new to realm.

I have a Realm Object with a boolean property whose default value set to false (let's call this schema version 1).

Person.schema = {
 primaryKey: 'id',
 properties:{
  working: {type: "bool", default: false}
 }
}

On version 2 of the schema, I have set the default to true and I want to migrate the changes if the current version of the user's app is less than 2.

so in the migration (oldRealm, newRealm) => part of the code i put this:

if (oldRealm.schemaVersion < 2) {
  const object = newRealm.objects('Person');
  for (const i in object) {
   const person: Person = object[i];
   person.working= true;
  } 
}

is this the correct approach? any help is welcome!

0

There are 0 answers