From 718c8d49ebbc9afc4e2c04e59c37e54e7a921b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81=C4=99picki?= Date: Sat, 27 May 2023 08:16:03 +0200 Subject: [PATCH] Apply filters before modifying query --- lib/flop.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/flop.ex b/lib/flop.ex index 5660ee2..7a1487c 100644 --- a/lib/flop.ex +++ b/lib/flop.ex @@ -772,8 +772,14 @@ defmodule Flop do if count = opts[:count] do count else - q = opts[:count_query] || count_query(q) - apply_on_repo(:aggregate, "count", [filter(q, flop, opts), :count], opts) + q = + if opts[:count_query] do + filter(opts[:count_query], flop, opts) + else + count_query(filter(q, flop, opts)) + end + + apply_on_repo(:aggregate, "count", [q, :count], opts) end end