Open bymaximus opened 4 years ago
orderBy([“user”, “updatedAt”])
Sent from my iPhone
On Nov 30, 2019, at 6:45 PM, bymaximus notifications@github.com wrote:
Is there some way to use orderBy with more than one field? For example, this orderBy(r.desc('fieldA'), r.desc('fieldB')) have different results from orderBy(r.desc('fieldA')).orderBy(r.desc('fieldB'))
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
orderBy([“user”, “updatedAt”])
This will order by ASC, seems the code is hardcoded to get the sort direction from the second element of the array, which makes impossible to use for example orderBy(r.desc('fieldA'), r.desc('fieldB'))
// Sort
if (query.orderBy) {
if (jsData.utils.isString(query.orderBy)) {
query.orderBy = [[query.orderBy, 'asc']];
}
for (var i = 0; i < query.orderBy.length; i++) {
if (jsData.utils.isString(query.orderBy[i])) {
query.orderBy[i] = [query.orderBy[i], 'asc'];
}
rql = (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? rql.orderBy(r.desc(query.orderBy[i][0])) : rql.orderBy(query.orderBy[i][0]);
}
}
Here's your 2 options:
orderBy(['user', 'DESC'])
// or
orderBy([ ['user', 'DESC'], ['updatedAt', 'asc']])
This lib looks like it needs some attention. @bymaximus if you'd like to help contribute to the code base here, I'm more than happy to help you push PR's along 👍🏽
Is there some way to use orderBy with more than one field? For example, this
orderBy(r.desc('fieldA'), r.desc('fieldB'))
have different results fromorderBy(r.desc('fieldA')).orderBy(r.desc('fieldB'))