Sorting based on reference elements

final tasks = realm.query<Task>('TRUEPREDICATE SORT(timeIntervals[0].startDate ASC)');

In short I want tasks to be sorted by datetime starting from newest, but information about datetime is in first List<$TimeInterval> object, which in my case is ObjectType.embeddedObject.

When I try to sort I receive "Error code: 3013 . Message: All but last property must be a link".
For now I have two options:
Use sort function, but in long list it will iterate every object freezing my UI.
Or second storing separate startDate in Task object and sort from there,

Maybe I am not aware of some realm queries, that might solve this problem.

The question is a little vague to me and it’s not clear what the expected result is. (I am probably reading it wrong so feel free to straighten me out)

In a list of sorted ascending timestamps the ‘newest’ will be the most recent; if that list is sorted from the newest ascending… it will only sort one element as there is only one most recent, and being the ‘last’ one in the list, will have nothing following it.

Then, a List is always ordered so why is the latest always at index 0, is it being inserted?


May not be the case. Realm objects are lazily loaded to sorting a very very (very) large list should have very little impact on the UI. However, if it does, an asynchronous or background task may be in order. I would test it first.