realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Support adding own methods to objects

Open emanuelez opened this issue 11 years ago • 68 comments

emanuelez avatar Feb 25 '15 09:02 emanuelez

See: https://groups.google.com/forum/#!searchin/realm-java/complex$20data$20types/realm-java/4XwofSl-iwU/30p8Y6JWt5EJ

emanuelez avatar Feb 25 '15 09:02 emanuelez

+1 for a modern db this should be possible. I've been doing it by starting the method names with 'get' but not sure if that's going to cause unexpected results? Seems to work, but full support would be nice to have.

Queatz avatar Mar 16 '15 05:03 Queatz

+1 my team is reconsidering the use of Realm for our app since we need custom logic in our getters & setters

carodelatorrehdz avatar Apr 06 '15 19:04 carodelatorrehdz

For reference (Five +1's from #637 has been transfered here).

cmelchior avatar Apr 15 '15 17:04 cmelchior

+1 would like to be able to use toString() method which is used in custom adapter a lot.

yolapop avatar Apr 16 '15 09:04 yolapop

+1 for ability to override at least toString() and equals() in RealmObject

HitOdessit avatar Apr 25 '15 09:04 HitOdessit

+1 must have feature

nmoskalenko avatar Apr 25 '15 09:04 nmoskalenko

+1

Any updates on this? Currently a lot of my code depends on custom methods like equals() which I cannot change easily (without making my own List class). Could it be explained why other methods cannot be defined in RealmObjects?

AndreasBackx avatar May 31 '15 19:05 AndreasBackx

+1

For me, this feature is a must-have :/ Is it planned ?

jlnquere avatar Jun 08 '15 07:06 jlnquere

+1 Can't override equals ??

danpe avatar Jun 13 '15 01:06 danpe

Right now how I work around this is by adding a getter for an ignored field

@Ignore
String method;

public String getMethod();

Verrrrrry temporary :)

Queatz avatar Jun 14 '15 06:06 Queatz

We are actively working on it and #1216 is part of the solution

emanuelez avatar Jun 17 '15 11:06 emanuelez

:+1: @emanuelez

quentin23soleil avatar Jun 17 '15 13:06 quentin23soleil

+1

nolanamy avatar Jul 10 '15 18:07 nolanamy

I've discovered this can be implemented using the existing realm code by using default methods in an interface (which can be utilized using the gradle-retrolambda plugin. For example a simplification of an interface of mine is:

public interface BaseModel {
    boolean isValid();
    void removeFromRealm();

    default String getUrlString() {
        return ModelType.get(this).toString() + "/" + getId();
    }

    String getId();
    void setId(String id);
}

By having my model classes implement BaseModel, I can use getUrlString without issue. This works due to the retrolambda plugin modifying code after the realm plugin. Like normal interfaces you can't define equals, toString, or hashCode, but this is a nice workaround until the folks at realm implement an official way. :)

iflatness avatar Jul 15 '15 23:07 iflatness

+1 I seriously can't use Realm until this is added. I would have to add another layer of model objects, and then use an object to object mapper, which defeats the purpose of Realm.

azizj1 avatar Jul 24 '15 01:07 azizj1

We are actively working on this :)

emanuelez avatar Jul 24 '15 08:07 emanuelez

Any information on when this will be ready for production?

AndreasBackx avatar Jul 24 '15 12:07 AndreasBackx

We can't promise a delivery date since we prioritize support first, then bug fixing, and finally the development of new features. Which means that the release date depends on the support load and the bugs to fix.

I know it might be unpleasant not being able to rely on a precise date, but focusing on support is really important to us.

emanuelez avatar Jul 25 '15 20:07 emanuelez

+1

shawnwall avatar Aug 10 '15 20:08 shawnwall