Thanks to you @Andrew_Meyer my realm setup is almost done. But there are few remainings things that I would like to ask / understand :
- I read that I can use an arrow function as default value when defining the schema, is there a way in this function to access a value defined in another field ? Because since I am keeping an history of changes I need 2 IDs fields in my objets, they must be the same at creation (and then after updates only one is changing).
So I would like to make something like :
rowId: { type: 'uuid', default: () => new BSON.UUID() }
branchId: { type: 'uuid', default: () => this.rowId }, // error because _this_ is not the realm object...`
- I also have a user Id in my objects, this id is retrieved from an async function, but that does not seems to be supported, any workaround for those âasyncâ situations ?
authorId: { type: 'uuid', default: () => async () => await User.userId() ?? new UUID('00000000-0000-4000-8000-000000000000') }
-
What would be the equivalent of willSave / didSave methods of Core Data framework ? Previously using Core Data I was able, thanks to these methods to performs things like : updating last modification time / author, duplicate the row being saved (in order to keep my changes history). perform encryption (at least with Realm I wonât have to do that part :))
-
The support of object classes by Realm is also unclear for me. If I have a class âAâ with a non static method âmethodâ, why do I get an âundefinedâ error when performing this kind of code :
const aObjects = realm.objects<A>(A.schema.name)
aObjects[0].method()
By the way, I am wondering if it is a good architecture to have helper methods for some queries inside those model classes files because they needs the Realm Instance to perform them but in my case those files are also included by the schema.ts, which is included by the RealmInstance.ts, so I end up having a require cycle, right ?
- And the last question: what is the difference between these 2 way to define Realm object classes ?
export abstract class MyRealmClass extends Realm.Object
VS
export abstract class MyRealmClass extends Realm.Object<MyRealmClass>
Thanks for your answers