-
Hi all, I am quite stumped on how to properly manage a collection when I am adding, updating, or deleting to a collection. Do I need to open the realm whenever I want to modify a collection? Whenever a collection is fetched, does the realm need to be open at all times (except when exiting/removing pages)? Right now I have a Thanks for any clarification. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Realm objects and collections are not copied into memory - instead data is read directly from the database when you read properties/indexes from them and is written directly to the database when you mutate them. This means that, yes, the Realm that owns an object/collection needs to be kept open for the lifetime of the object/collection. Generally, Realm is not a great fit for a repository pattern, because it relies heavily on lazy-loading and reactivity. You can achieve it by copying the data from the database into unmanaged objects either manually or using automapper, but doing so will lose out on a lot of the benefits of using Realm. |
Beta Was this translation helpful? Give feedback.
Realm objects and collections are not copied into memory - instead data is read directly from the database when you read properties/indexes from them and is written directly to the database when you mutate them. This means that, yes, the Realm that owns an object/collection needs to be kept open for the lifetime of the object/collection.
Generally, Realm is not a great fit for a repository pattern, because it relies heavily on lazy-loading and reactivity. You can achieve it by copying the data from the database into unmanaged objects either manually or using automapper, but doing so will lose out on a lot of the benefits of using Realm.