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

Sort/Order by nested #161

Open
Secretmapper opened this issue Aug 4, 2018 · 1 comment
Open

Sort/Order by nested #161

Secretmapper opened this issue Aug 4, 2018 · 1 comment

Comments

@Secretmapper
Copy link

How would I run a query similar to: sort({'embedded.field': -1})?

I have tried order_by(desc: "embedded.field") and order_by(fragment("embedded.field")) doesn't work.

@rhcarvalho
Copy link

I was trying to get a similar query to work, and after some trial and error I think I found something that works:

from(c in SomeEctoSchema,
  # ...
  order_by: [desc: c."embedded.field"],
  # ...
)
|> MyApp.Repo.all()

The logs print:

{"$orderby", ["embedded.field": -1]}

And I get apparently correct results.

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