Support super classing for Realm.Object model
Problem
Currently the model class must be direct descendant of Realm.Object class,
But creating many model class with repetitive field or methods could be exhausting (for example when all model should have _id, and createdAt field), so i tried to create a super class BaseModel which extends Realm.Object to handle that common fields and methods, then i would write my actual model extending that BaseModel
In this case i created UserPreference Model extending BaseModel
but then realm throw error like this
[Error: Exception in HostFunction: Class 'UserPreference' (declaring 'user_preference' schema) must extend Realm.Object]
Edit, i forgot to put my specs
"@realm/react": "^0.4.1",
"react": "^18.2.0",
"react-native": "0.70.6",
"realm": "^11.3.0"
Solution
for now i have to rewrite the BaseModel as an Interface, and the model implements it, so i don't miss the basic field that all of my models should have, but at the cost of repetitive code
How important is this improvement for you?
Fairly niche, but nice to have anyway.
@deckyfx Thank you for the suggestion. I agree that superclassing is the next natural step. It does also come up in other Realm SDKs, and it is a feature we would like to implement. I can't give us an estimate for when.
Got the same problem here. It would be great if we could superclassing the models.