diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-04-10 02:59:23 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-04-11 07:57:10 +0900 |
commit | eae0ab97b2f8fdb3f7d62fa14642c54421edc4ff (patch) | |
tree | 6c103206056e1fd504741e0d8ad83f98beed20fd /activerecord/lib/active_record/relation | |
parent | 8170bcd99ad3ee4ac4ddf9e28a7c2a5fb93f1b0c (diff) | |
download | rails-eae0ab97b2f8fdb3f7d62fa14642c54421edc4ff.tar.gz rails-eae0ab97b2f8fdb3f7d62fa14642c54421edc4ff.tar.bz2 rails-eae0ab97b2f8fdb3f7d62fa14642c54421edc4ff.zip |
`AssociationQueryValue#queries` returns an array for more concise association handling
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 19 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb | 2 |
2 files changed, 7 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index f2e719363c..133b3d837c 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -81,7 +81,7 @@ module ActiveRecord end def create_binds_for_hash(attributes) - result = {} + result = attributes.dup binds = [] attributes.each do |column_name, value| @@ -105,17 +105,11 @@ module ActiveRecord end end - if klass - result[column_name] = klass.new(associated_table, value).queries.map do |query| - attrs, bvs = create_binds_for_hash(query) - binds.concat(bvs) - attrs - end - else - queries = AssociationQueryValue.new(associated_table, value).queries - attrs, bvs = create_binds_for_hash(queries) - result.merge!(attrs) + klass ||= AssociationQueryValue + result[column_name] = klass.new(associated_table, value).queries.map do |query| + attrs, bvs = create_binds_for_hash(query) binds.concat(bvs) + attrs end when value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype) first = value.begin @@ -132,12 +126,11 @@ module ActiveRecord result[column_name] = RangeHandler::RangeWithBinds.new(first, last, value.exclude_end?) else if can_be_bound?(column_name, value) + result[column_name] = Arel::Nodes::BindParam.new binds << build_bind_param(column_name, value) - value = Arel::Nodes::BindParam.new elsif value.is_a?(Relation) binds.concat(value.bound_attributes) end - result[column_name] = value end end diff --git a/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb index cc39aff91a..2fe0f81cab 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb @@ -9,7 +9,7 @@ module ActiveRecord end def queries - { associated_table.association_foreign_key.to_s => ids } + [associated_table.association_foreign_key.to_s => ids] end private |