scrivener_ecto icon indicating copy to clipboard operation
scrivener_ecto copied to clipboard

Fix total entries when query has combinations

Open oo6 opened this issue 4 years ago • 1 comments
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.

oo6 avatar Aug 26 '21 14:08 oo6

@drewolson Hi! Do you have time to review this PR? I look forward to finishing it, thanks.

oo6 avatar Jan 17 '22 13:01 oo6