vicpinm / Kotlin-Realm-Extensions

Kotlin extensions to simplify Realm API.
Apache License 2.0
535 stars 53 forks source link

Support for RealmModel #22

Closed AdamGrzybkowski closed 6 years ago

AdamGrzybkowski commented 7 years ago

What do you think about adding support for RealmModel interface?

I'm not 100% sure if this would be important to other users, because even if you only implement RealmModel and add RealmClass annotation you still cannot extend from different classes then RealmObject. But still there may be some users that prefer this approach.

If you think this would be a nice to have feature I can prepare a PR to discuss :)

vicpinm commented 7 years ago

Hi @AdamGrzybkowski, I have never use RealmModel, but I think it could be an interesting feature. I will try to prepare some examples to see how it works!

AdamGrzybkowski commented 7 years ago

@vicpinm After I've created this issue I tried to do it as proof of concept. You can check it here https://github.com/AdamGrzybkowski/Kotlin-Realm-Extensions/commit/32df7cf0e9360e72800525ab84b8ef092030865e

It should be pretty simple because RealmObject is implementing RealmModel. The only difference is when you want to check e.g. if object is valid or managed.

vicpinm commented 7 years ago

Thanks you so much @AdamGrzybkowski, I will look into it next week! I also have to see how it works with new realm version 4.0.

magillus commented 7 years ago

The RealmModel would work nice with Separate RealmConfiguration - that is where they are used. Something that I had on mind to add, but no time yet. It would work with https://github.com/vicpinm/Kotlin-Realm-Extensions/blob/master/library/src/main/java/com/vicpin/krealmextensions/RealmConfigStore.kt

So definition would not need to be per RealmObject's class but per RealmModel.

vicpinm commented 6 years ago

@magillus PR is now merged into master. A new version will be upload soon to maven.