I'm using Bookshelf.js/Knex.js, fetching a model (call it user) with a related child model (call it company).
Can I order by a field on the child model - company.name
?
Also, if that's possible, can I multi sort, say company.name
descending then lastName
ascending
Here's my current code, which only works on root model fields. qb.orderBy('company.name', 'desc')
doesn't work.
users.query(function(qb) {
qb.orderBy('lastName', 'asc');
})
.fetch({withRelated: ['company']})
.then(success, error);