diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-13 21:30:19 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 21:30:19 +0900 |
commit | 823f9e0a89707561b54196bf4aabe20c5edb88c1 (patch) | |
tree | 82b66bc3d46f5554f10e13e0a2bf598438885eb1 /activerecord/lib/active_record/relation | |
parent | 7db3a6e89a05855d6f55864e15ee69986708c1dc (diff) | |
parent | a50eacb03cf3df1d1cbc227ea0115901e0327f1c (diff) | |
download | rails-823f9e0a89707561b54196bf4aabe20c5edb88c1.tar.gz rails-823f9e0a89707561b54196bf4aabe20c5edb88c1.tar.bz2 rails-823f9e0a89707561b54196bf4aabe20c5edb88c1.zip |
Merge pull request #33844 from kamipo/too_many_eager_load_ids
Eager loading/preloading should be worked regardless of large number of records
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder/array_handler.rb | 9 |
2 files changed, 10 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index f734cd0ad8..cb70b8bcde 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -57,10 +57,14 @@ module ActiveRecord end def build_bind_attribute(column_name, value) - attr = Relation::QueryAttribute.new(column_name.to_s, value, table.type(column_name)) + attr = build_query_attribute(column_name, value) Arel::Nodes::BindParam.new(attr) end + def build_query_attribute(column_name, value) + Relation::QueryAttribute.new(column_name.to_s, value, table.type(column_name)) + end + protected def expand_from_hash(attributes) return ["1=0"] if attributes.empty? diff --git a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb index e5191fa38a..0895b9fba6 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb @@ -21,10 +21,11 @@ module ActiveRecord when 0 then NullPredicate when 1 then predicate_builder.build(attribute, values.first) else - bind_values = values.map do |v| - predicate_builder.build_bind_attribute(attribute.name, v) - end - attribute.in(bind_values) + values.map! do |v| + attr = predicate_builder.build_query_attribute(attribute.name, v) + attr.value_for_database if attr.boundable? + end.compact! + values.empty? ? NullPredicate : attribute.in(values) end unless nils.empty? |