Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support super classing for Realm.Object model #5170

Open
deckyfx opened this issue Dec 9, 2022 · 3 comments
Open

Support super classing for Realm.Object model #5170

deckyfx opened this issue Dec 9, 2022 · 3 comments

Comments

@deckyfx
Copy link

deckyfx commented Dec 9, 2022

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.

@kneth
Copy link
Contributor

kneth commented Dec 9, 2022

@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.

@fkranenburg
Copy link
Contributor

Got the same problem here. It would be great if we could superclassing the models.

@deckyfx
Copy link
Author

deckyfx commented Apr 15, 2024

Why this ticket is closed, is this already supported? or auto-closed?

Edit: move to discussion 6615

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants