nicklandgrebe/active-resource.js

[Q] How to sort/order by association.attribute

CharlieIGG opened this issue · 1 comments

Before anything else: Thanks for the very cool library!
—–––––––––––––––––––––––––––––––
How can we create queries that sort by attributes in our resource's relationships?

Say for instance I have the resource Cars with a belongsTo('make') relationship.
I would like to be able to create a query where I get the cars sorted by their associated makes' name, something like this:

const carsCollection = await Resources.Car.includes("make").order({
            "make.name": "desc"
        }).all();

Is this doable?

For anyone interested, the above works just fine, as long as your back-end side implementation of JSON:API is configured to handle this.