Skip to content

Fix total_pages method fail on active_record model after calling merge with unscoped limit#652

Open
allomov wants to merge 1 commit into
mislav:masterfrom
allomov:fix_nil_limit_value_in_total_page
Open

Fix total_pages method fail on active_record model after calling merge with unscoped limit#652
allomov wants to merge 1 commit into
mislav:masterfrom
allomov:fix_nil_limit_value_in_total_page

Conversation

@allomov

@allomov allomov commented Jul 19, 2023

Copy link
Copy Markdown

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