tekartik / sembast.dart

Simple io database
BSD 2-Clause "Simplified" License
763 stars 63 forks source link

Ordering by property of nested array object #344

Closed acorn371 closed 1 year ago

acorn371 commented 1 year ago

Hi, as for issue #12 (closed) I'm having trouble about sorting by a nested object. In my specific case, nested objects are arrays of objects and I would like to order-by a field in the array object. My sembast store contains book instances like :

{
        "id": 1,
    "title": "book title",
    "editions": [
        {
            "published": "publishing date", 
            "edition_title": "a specific edition title",
            ...
        }
    ],
    ...
}

and I would like to sort by the "edition_title" field of the first array item. When I call await store.find(db, finder: Finder(sortOrders: [SortOrder("editions.edition_title")])) I get all the store items apparently sorted by the id field. Is there a specific syntax for the SortOrder i need ?

I'm using flutter 3.7.6 and I tried sembast 3.2.0+1 and 3.4.0+6. Thanks.

alextekartik commented 1 year ago

I added support for accessing inner list item in sembast 3.4.1-0. You should be able to use the following sort order:

SortOrder("editions.0.edition_title")]
acorn371 commented 1 year ago

Great! Thank You so much!.