RealmInsertionModel

I have a Realm Model as follows:

export type List = {
  _id: Realm.BSON.ObjectId;
  allowedUserIds: Array<string>;
  allowedUserNotifications: Array<AllowedUserNotification>;
  date?: Date;
  isActive?: boolean;
  listItems: Realm.List<ListItem>;
  name: string;
  userId: string;
};

In a previous version of Realm, I used the following to instantiate an instance of this model:

    const list: RealmInsertionModel<List> = {
      _id: new ObjectId(),
      allowedUserIds: [],
      name,
      date: adjustedDate,
      isActive: true,
      listItems: [],
      userId: currentUser?.id ?? "1",
      allowedUserNotifications: []
    };

However, with the latest version of Realm, RealmInsertionModel not longer appears to be available.

My question is how do I now instantiate an instance of a model that includes Realm.List?

Thanks,

Tony

I resolved. It turns out I can just add the object as follows:

    const item = listRealm?.create<List>("List",
    {
      _id: new ObjectId(),
      allowedUserIds: [],
      name,
      date: adjustedDate,
      isActive: true,
      listItems: [],
      userId: currentUser?.id ?? "1",
      allowedUserNotifications: []     
    },
    Realm.UpdateMode.All
  );
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.