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

An orderBy function cannot be called more than once in the same query expression #266

Closed
jaynarw opened this issue Jul 30, 2021 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jaynarw
Copy link

jaynarw commented Jul 30, 2021

Error:

An orderBy function cannot be called more than once in the same query expression

Code:

Comments
  .orderByDescending("pinned")
  .orderByDescending("timestamp")
  .limit(n)
  .find()

Firestore allows ordering using multiple fields in the same query.
Firebase Docs:

You can also order by multiple fields. For example, if you wanted to order by state, and within each state order by population in descending order:

Workaround: use customQuery to orderBy other fields.

@wovalle wovalle added the bug Something isn't working label Jul 31, 2021
@wovalle
Copy link
Owner

wovalle commented Aug 2, 2021

Interesting. In https://github.com/wovalle/fireorm/blob/master/src/QueryBuilder.ts#L147 and https://github.com/wovalle/fireorm/blob/master/src/QueryBuilder.ts#L162 we should store the fields that have been ordered by with (and throw if you try to orderBy twice in the same field) instead of just checking if any fields have been ordered by.

@wovalle wovalle added the good first issue Good for newcomers label Aug 2, 2021
jomendez pushed a commit to jomendez/fireorm that referenced this issue Nov 11, 2021
Description:
Store the fields that have been ordered by with (and throw if you try to
orderBy twice in the same field) instead of just checking if any fields
have been ordered by.
An orderBy function cannot be called more than once in the same query
expression, except on different fields.

Fixing issue wovalle#266
@wovalle wovalle closed this as completed Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants