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_pages method fail on active_record model after calling merge with unscoped limit #652

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

Conversation

allomov
Copy link

@allomov allomov commented Jul 19, 2023

It has been observed that using active record .merge can result in having .limit_value as nil. This can cause .total_entries and .total_pages to fail with the error comparison of Integer with nil failed on the following line:

if loaded? and size < limit_value and (current_page == 1 or size > 0)

Here is an example that demonstrates how you can get a nil value in the limit_value field:

User.limit(10).limit_value
# => 10
User.joins(:role).limit(10).merge(Role.all.unscope(:limit)).limit_value
# => nil

There are two places that require updates:

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.

1 participant