Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix total entries when query has combinations #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oo6
Copy link

@oo6 oo6 commented Aug 26, 2021

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
Copy link
Author

oo6 commented Jan 17, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant