Start a new topic

Kinvey.Query._postProcess supporting nested properties for sorting

I noticed that Kinvey.Query was not sorting data correctly when I fetched it with {offline: true}. After some debugging, I found that the Kinvey.Query._postProcess function has a comment saying it doesn't support sorting by nested fields. My first thought was, "Fair enough, it's probably a niche feature that wasn't worth implementing", but then I noticed that the function immediately below it in the source code (nested) already does the dirty work by digging out the nested property. From my (perhaps naïve) perspective, it seems like it wouldn't be too much work to switch "a[field]" to "nested(a, field)" to allow _postProcess to sort by nested fields. What do you think?

As a side note, it's a pity IndexedDB doesn't give better control over sorting..

The `_postProcess` function does not dig out nested properties, but just uses the top-level. It does support sorting by multiple fields though.

If this is a common use case for you, I can enhance the method to actually sort correctly when given a `dot.separated.field`. And yes, IndexedDB is unfortunately pretty basic, requiring a lot of code on top to make it actually useful.
Hi Mark, if it's not too much work and doesn't have a noticeable impact on performance for the more common non-nested case, then I would certainly appreciate it :)
Noted, I’ll see if I can include it in the next release of the library.
This is now in the [1.1.5 release](
Awesome sauce. Thanks a lot!
Login or Signup to post a comment