diff options
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 90e4fe98d5..1c4011b75e 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -53,7 +53,7 @@ module ActiveRecord im = arel.create_insert im.into @table - substitutes, binds = substitute_values values + substitutes = substitute_values values if values.empty? # empty insert im.values = Arel.sql(connection.empty_insert_statement_value) @@ -67,11 +67,11 @@ module ActiveRecord primary_key || false, primary_key_value, nil, - binds) + ) end def _update_record(values, id, id_was) # :nodoc: - substitutes, binds = substitute_values values + substitutes = substitute_values values scope = @klass.unscoped @@ -80,7 +80,6 @@ module ActiveRecord end relation = scope.where(@klass.primary_key => (id_was || id)) - bvs = binds + relation.bound_attributes um = relation .arel .compile_update(substitutes, @klass.primary_key) @@ -88,20 +87,14 @@ module ActiveRecord @klass.connection.update( um, "SQL", - bvs, ) end def substitute_values(values) # :nodoc: - binds = [] - substitutes = [] - - values.each do |arel_attr, value| - binds.push QueryAttribute.new(arel_attr.name, value, klass.type_for_attribute(arel_attr.name)) - substitutes.push [arel_attr, Arel::Nodes::BindParam.new] + values.map do |arel_attr, value| + bind = QueryAttribute.new(arel_attr.name, value, klass.type_for_attribute(arel_attr.name)) + [arel_attr, Arel::Nodes::BindParam.new(bind)] end - - [substitutes, binds] end def arel_attribute(name) # :nodoc: @@ -380,7 +373,7 @@ module ActiveRecord stmt.wheres = arel.constraints end - @klass.connection.update stmt, "SQL", bound_attributes + @klass.connection.update stmt, "SQL" end # Updates an object (or multiple objects) and saves it to the database, if validations pass. @@ -510,7 +503,7 @@ module ActiveRecord stmt.wheres = arel.constraints end - affected = @klass.connection.delete(stmt, "SQL", bound_attributes) + affected = @klass.connection.delete(stmt, "SQL") reset affected @@ -578,7 +571,8 @@ module ActiveRecord conn = klass.connection conn.unprepared_statement { - conn.to_sql(relation.arel, relation.bound_attributes) + sql, _ = conn.to_sql(relation.arel) + sql } end end @@ -648,6 +642,10 @@ module ActiveRecord @values == klass.unscoped.values end + def has_limit_or_offset? # :nodoc: + limit_value || offset_value + end + protected def load_records(records) @@ -663,7 +661,7 @@ module ActiveRecord def exec_queries(&block) skip_query_cache_if_necessary do - @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, bound_attributes, &block).freeze + @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, &block).freeze preload = preload_values preload += includes_values unless eager_loading? |