Skip to content

Commit

Permalink
Ignore ActiveModel::RangeError in Ransack conditions
Browse files Browse the repository at this point in the history
Fixes #1337
  • Loading branch information
JunichiIto committed Jun 10, 2022
1 parent 6f830ba commit b24fb75
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/ransack/adapters/active_record/ransack/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def arel_predicate
}.reduce(combinator_method)

if replace_right_node?(predicate)
# Replace right node object to plain Integer value in order to avoid
# Replace right node object to plain integer value in order to avoid
# ActiveModel::RangeError from Arel::Node::Casted.
# The error can be ignored here because RDBMSs accept large numbers
# in condition clauses.
Expand Down Expand Up @@ -73,8 +73,9 @@ def replace_right_node?(predicate)
arel_node = predicate.right
return unless arel_node.is_a?(Arel::Nodes::Casted)

relation_type = arel_node.attribute.relation.type_for_attribute(arel_node.attribute.name).type
relation_type == :integer && arel_node.value.is_a?(Integer)
relation, name = arel_node.attribute.values
attribute_type = relation.type_for_attribute(name).type
attribute_type == :integer && arel_node.value.is_a?(Integer)
end

end
Expand Down

0 comments on commit b24fb75

Please sign in to comment.