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

fixes without_count last_page? behaviour #1009

Merged
merged 8 commits into from Jan 17, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -59,11 +59,11 @@ def load
else
@values[:limit] = limit_value + 1
# FIXME: this could be removed when we're dropping AR 4 support
@arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
@arel.limit = adjusted_limit(@values[:limit]) if @arel && adjustable?(@arel.limit)
super
@values[:limit] = limit_value - 1
# FIXME: this could be removed when we're dropping AR 4 support
@arel.limit = @values[:limit] if @arel && (Integer === @arel.limit)
@arel.limit = adjusted_limit(@values[:limit]) if @arel && adjustable?(@arel.limit)

if @records.any?
@records = @records.dup if (frozen = @records.frozen?)
Expand All @@ -75,6 +75,21 @@ def load
end
end

def adjustable?(obj)
return true if obj.class == Integer || obj.class == Fixnum
return true if obj.class == Arel::Nodes::BindParam && obj.respond_to?(:value)
false
montdidier marked this conversation as resolved.
Show resolved Hide resolved
end

def adjusted_limit(limit)
case @arel.limit.class
when Integer, Fixnum
limit
when Arel::Nodes::BindParam
Arel::Nodes::BindParam.new(@arel.limit.value.with_cast_value(limit))
end
end

# The page wouldn't be the last page if there's "limit + 1" record
def last_page?
!out_of_range? && !@_has_next
Expand Down