Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@edraut
Copy link

@edraut edraut commented Nov 25, 2018

For some reason in my app ActiveRecord is not removing the select when executing a count. I know this because PostgreSQL is giving an explicit error message showing that ActiveRecord is trying to do both the count and the custom select.

Explicitly telling ActiveRecord to remove the select fixes my problem.

I have attached a stack trace of the failure in my app. After many hours of trying, I cannot create a test case that elicits this problem in the Kaminari test suite. The differences between my very large app and the Kaminari test app are too great and the specific failing example involves some extremely complex AREL.

Anyhow, would you be willing to add this explicit removal of the select clause when counting? It is always good to remove the select when counting, and apparently we cannot trust ActiveRecord to remove it automatically in every case, even if I can't work out the exact permutation to elicit the bug in ActiveRecord.

Thank you for your consideration!
Eric
kaminari_stack_trace.txt

@yuki24
Copy link
Member

yuki24 commented Feb 1, 2019

I'm sorry for not getting back sooner. I think when the DISTINCT clause is present you still could get a greater total count than it should, since DISTINCT is supposed to remove duplicates and removing the entire SELECT would bring back duplicates. Instead, we may want to generate a SQL query that respects the DISTINCT to generate the correct total count without throwing an error.

It'd be greatly appreciated if you could add a few tests that cover these cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants