scrivener_ecto
scrivener_ecto copied to clipboard
Fix total entries when query has combinations
trafficstars
Currently, Repo.paginate may throw an exception if the query has combinations.
Test case:
Post
|> Post.published()
|> union(^Post.unpublished(Post))
|> Scrivener.Ecto.Repo.paginate()
Exception message:
** (Postgrex.Error) ERROR 42601 (syntax_error) each UNION query must have the same number of columns
query: SELECT count('*') FROM "posts" AS p0 WHERE (p0."published" = TRUE) UNION (SELECT p0."id", p0."title", p0."body", p0."published", p0."inserted_at", p0."updated_at" FROM "posts" AS p0 WHERE (p0."published" = FALSE))
Inspiration from ecto, I direct use Ecto.Query.aggregate to count total entries except query has group_bys.
@drewolson Hi! Do you have time to review this PR? I look forward to finishing it, thanks.