Skip to content

Commit

Permalink
Extract build_cast_value for limit_value and offset_value
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed May 3, 2020
1 parent d1d98f3 commit 8eb940b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions activerecord/lib/active_record/relation/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1096,20 +1096,10 @@ def build_arel(aliases)
arel.where(where_clause.ast) unless where_clause.empty?
arel.having(having_clause.ast) unless having_clause.empty?
if limit_value
limit_attribute = ActiveModel::Attribute.with_cast_value(
"LIMIT",
connection.sanitize_limit(limit_value),
Type.default_value,
)
arel.take(Arel::Nodes::BindParam.new(limit_attribute))
arel.take(build_cast_value("LIMIT", connection.sanitize_limit(limit_value)))
end
if offset_value
offset_attribute = ActiveModel::Attribute.with_cast_value(
"OFFSET",
offset_value.to_i,
Type.default_value,
)
arel.skip(Arel::Nodes::BindParam.new(offset_attribute))
arel.skip(build_cast_value("OFFSET", offset_value.to_i))
end
arel.group(*arel_columns(group_values.uniq.compact_blank)) unless group_values.empty?

Expand All @@ -1126,6 +1116,11 @@ def build_arel(aliases)
arel
end

def build_cast_value(name, value)
cast_value = ActiveModel::Attribute.with_cast_value(name, value, Type.default_value)
Arel::Nodes::BindParam.new(cast_value)
end

def build_from
opts = from_clause.value
name = from_clause.name
Expand Down

0 comments on commit 8eb940b

Please sign in to comment.