findInNewRealm<T extends RealmObject> method

T? findInNewRealm<T extends RealmObject>(
  1. RealmObject oldObject
)

Finds an object obtained from oldRealm in newRealm. This is useful when you are working with objects without primary keys and want to update some information about the object as part of the migration.

Implementation

T? findInNewRealm<T extends RealmObject>(RealmObject oldObject) {
  if (!oldObject.isManaged) {
    throw UnsupportedError('Only managed RealmObject instances can be looked up in the new Realm');
  }

  final metadata = newRealm.metadata.getByType(T);
  final handle = realmCore.findExisting(newRealm, metadata.classKey, oldObject.handle);
  if (handle == null) {
    return null;
  }

  final accessor = RealmCoreAccessor(metadata, true);
  var object = RealmObjectInternal.create(T, newRealm, handle, accessor);
  return object as T;
}