Realm-java: Reenable `between()` for link queries

Created on 1 Feb 2016  路  12Comments  路  Source: realm/realm-java

Realm core 0.96.0 has an implementation of between() for link queries.

T-Enhancement

Most helpful comment

@kneth ah, you're right >.< I made that mistake, he'd have to do

 realm.where(Item.class)
     .greaterThanOrEqualTo("record.date",beforeDate)
     .findAll()
     .where()
     .lessThanOrEqualTo("record.date",curDate)
     .findAll();

All 12 comments

So how can I retrieve data from Item table based on date which is store in Record Table ..
Is any logic help to solve this issue.. Please help me..Thank you,

If your Item has a Record record; field, then you can use lowerThan and greaterThan with a link query

realm.where(Item.class).greaterThan("record.date", someDate).lessThan(...).findAll();

@Zhuinden
realm.where(Item.class).greaterThanOrEqualTo("record.date",beforeDate).lessThanOrEqualTo("record.date",curDate).findAll();

Its not worked.. i have tried lot..please help..

Please define "not worked", I do not know what went wrong. 馃槙

getting RealmList size zero.. though it has records to display..

you mean RealmResults藱?

yes..please help..

@dtmandroid At first, link queries often don't work as excepted. The reason is that a link query returns a parent object if at least one child object is meeting the query condition. We have documented this behaviour in https://realm.io/docs/java/latest/#link-queries. Rewriting between() and greaterThanOrEqual().lessThanOrEqual() will not produce the result as you though you would get.

@kneth ah, you're right >.< I made that mistake, he'd have to do

 realm.where(Item.class)
     .greaterThanOrEqualTo("record.date",beforeDate)
     .findAll()
     .where()
     .lessThanOrEqualTo("record.date",curDate)
     .findAll();

The description indicates that Realm Core has support for it but not through a simple function. We can draw inspiration from Realm Cocoa's implementation: https://github.com/realm/realm-cocoa/blob/master/Realm/RLMQueryUtil.mm#L743

@Zhuinden It is necessary to call findAll() twice?

ah, you're right >.< I made that mistake, he'd have to do

 realm.where(Item.class)
     .greaterThanOrEqualTo("record.date",beforeDate)
     .findAll()
     .where()
     .lessThanOrEqualTo("record.date",curDate)
     .findAll();

Yes

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gpulido picture gpulido  路  3Comments

Merlin1993 picture Merlin1993  路  3Comments

nolanamy picture nolanamy  路  3Comments

AlbertVilaCalvo picture AlbertVilaCalvo  路  3Comments

pawlo2102 picture pawlo2102  路  3Comments