aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-08-07 00:41:24 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-08-11 22:30:40 +0900
commitf79d55a4cca155171c6d16c3c07834ba43d572c2 (patch)
tree8b3fd9e852f7a619f8011ce131b7ce14f6e8d5c3 /activerecord/lib/active_record/relation
parentb9f71e49ae43c53258da95bda50325a8d0c99a52 (diff)
downloadrails-f79d55a4cca155171c6d16c3c07834ba43d572c2.tar.gz
rails-f79d55a4cca155171c6d16c3c07834ba43d572c2.tar.bz2
rails-f79d55a4cca155171c6d16c3c07834ba43d572c2.zip
`where` by `array|range` attribute with array or range value
Currently predicate builder cannot build a predicate for `array|range` attribute. This commit fixes the issue. Related #25671.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 505a78cb78..9d6fc9f702 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -87,14 +87,14 @@ module ActiveRecord
binds = []
attributes.each do |column_name, value|
- case value
- when Hash
+ case
+ when value.is_a?(Hash)
attrs, bvs = associated_predicate_builder(column_name).create_binds_for_hash(value)
result[column_name] = attrs
binds += bvs
- when Relation
+ when value.is_a?(Relation)
binds += value.bound_attributes
- when Range
+ when value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype)
first = value.begin
last = value.end
unless first.respond_to?(:infinite?) && first.infinite?
@@ -155,9 +155,13 @@ module ActiveRecord
end
def can_be_bound?(column_name, value)
- !value.nil? &&
- handler_for(value).is_a?(BasicObjectHandler) &&
- !table.associated_with?(column_name)
+ return if table.associated_with?(column_name)
+ case value
+ when Array, Range
+ table.type(column_name).respond_to?(:subtype)
+ else
+ !value.nil? && handler_for(value).is_a?(BasicObjectHandler)
+ end
end
def build_bind_param(column_name, value)