Skip to content

How do I perform an aggregated SQL query like sum on the filtered query? #347

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

You must be logged in to vote

That sounds as if you're not passing the for option to the filter function, in which case Flop wouldn't know about the custom field. If you use multiple of the Flop functions, it's always a good idea to assign the necessary opts to a variable and pass it to each function. In your case, probably something like this:

flop_opts = [for: MyApp.Invoice]

with {:ok, flop} <- Flop.validate(params, flop_opts) do
  MyApp.Invoice
  |> Flop.filter(flop, flop_opts)
  |> ...
end

If all you want to do is to disable pagination, you can also do this:

Flop.validate_and_run(MyApp.Invoice, params, for: MyApp.Invoice, pagination: false)

or in your case, probably something similar to:

MyApp.Invoice
|> select([i],

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by joerichsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants