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

Using dynamics for ordering queries #3257

Closed
Svenito opened this issue Mar 27, 2020 · 0 comments
Closed

Using dynamics for ordering queries #3257

Svenito opened this issue Mar 27, 2020 · 0 comments

Comments

@Svenito
Copy link

Svenito commented Mar 27, 2020

Environment

  • Elixir version (elixir -v):
    Elixir 1.10.2 (compiled with Erlang/OTP 21)

  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.):
    PostgreSQL 12.2

  • Ecto version (mix deps):
    3.3.4

  • Database adapter and version (mix deps):
    ecto_sql 3.3.4

  • Operating system:
    KDE Neon

The documentation at https://hexdocs.pm/ecto/dynamic-queries.html#building-dynamic-queries shows how to use dynamics for ordering results. I have tried this and while

dynamic([q], field(q, :id))

works, when trying to set the sort direction like this

dynamic([q], desc: field(q, :id))

results in the following error:

** (Ecto.Query.CompileError) Tuples can only be used in comparisons with literal tuples of the same size

I've asked this question on the Elixir forum and have a working solution, but it would seem that either the docs are inaccurate, or the feature mentioned isn't working as expected

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

1 participant