Skip to content

Question regarding ecto's group_by #298

Answered by woylie
tkaretsos asked this question in Q&A
Discussion options

You must be logged in to vote

Interesting, I haven't used group by clauses in combination with Flop before. The error is caused because by default, Flop takes the final query (minus pagination and order parameters) and runs a count query using Ecto.Repo.aggregate, which does not support group by.

You can get around this by passing a custom count query that does not include a group by clause:

count_query = distinct(MyApp.Foo, [f], f.period_start)
Flop.validate_and_run(Foo, params, for: Foo, count_query: count_query)

Or if you need to to apply Flop filters:

with {:ok, flop} <- Flop.validate(params, for: Foo) do
  count_query = MyApp.Foo |> Flop.filter(flop, for: Foo) |> distinct([f], f.period_start)
  {:ok, Flop.run(Foo, 

Replies: 5 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@tkaretsos
Comment options

Answer selected by tkaretsos
Comment options

You must be logged in to vote
5 replies
@woylie
Comment options

@michallepicki
Comment options

@michallepicki
Comment options

@a3kov
Comment options

@a3kov
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
4 participants