nicklandgrebe / active-resource.js

ActiveResource.js - API resource relational mapping in JavaScript
https://active-resource.js.org
MIT License
133 stars 20 forks source link

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

Closed CharlieIGG closed 5 years ago

CharlieIGG commented 5 years ago

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?

CharlieIGG commented 5 years ago

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