realm-kotlin
realm-kotlin copied to clipboard
Calling sort().first().find() doesn't work
Want to sort a list and retrieve the first one with sort().first().find()
but it doesn't work.
Using sort().find().firstOrNull()
will work instead.
@ganfra When you say it doesn't work, what do you mean exactly? Can you share an example?
Yes sorry, I was not clear.
So the result is not returned sorted as I'd have expected.
But if I just call find().firstOrNull()
instead it respects the sort operator.
Exemple:
class Task : RealmObject {
@PrimaryKey
var id: Long = 0,
var name: String = ""
var lastEditTs: Long = 0
}
If I want to get the latest edited task:
realm.query(Task::class).sort("lastEditTs", Sort.DESCENDING).first().find()
=> will return the first edited
realm.query(Task::class).sort("lastEditTs", Sort.DESCENDING).find().firstOrNull()
=> will return the last edited
@ganfra Thanks for the clarification, we were able to reproduce the issue.