Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orderBy multiple fields #30

Open
bymaximus opened this issue Dec 1, 2019 · 4 comments
Open

orderBy multiple fields #30

bymaximus opened this issue Dec 1, 2019 · 4 comments

Comments

@bymaximus
Copy link

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'))

@crobinson42
Copy link
Member

crobinson42 commented Dec 1, 2019 via email

@bymaximus
Copy link
Author

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]);
      }
    }

@crobinson42
Copy link
Member

crobinson42 commented Dec 1, 2019

Here's your 2 options:

orderBy(['user', 'DESC'])
// or
orderBy([ ['user', 'DESC'], ['updatedAt', 'asc']])

@crobinson42
Copy link
Member

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 👍🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants