Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding bind values to the manager object

  • Loading branch information...
commit 9b5d603c5aaa91f1d7a67a014d3ac680ad07577f 1 parent 3086881
@tenderlove tenderlove authored
View
7 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -67,12 +67,9 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
left.merge right
end
- if rel
+ if rel && !rel.arel.constraints.empty?
bind_values.concat rel.bind_values
-
- if !rel.arel.constraints.empty?
- constraint = constraint.and rel.arel.constraints
- end
+ constraint = constraint.and rel.arel.constraints
end
joins << table.create_join(table, table.create_on(constraint), join_type)
View
2  activerecord/lib/active_record/relation.rb
@@ -608,7 +608,7 @@ def inspect
private
def exec_queries
- @records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel, bind_values)
+ @records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel, arel.bind_values + bind_values)
preload = preload_values
preload += includes_values unless eager_loading?
View
6 activerecord/lib/active_record/relation/calculations.rb
@@ -235,11 +235,14 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
column_alias = column_name
+ bind_values = nil
+
if operation == "count" && (relation.limit_value || relation.offset_value)
# Shortcut when limit is zero.
return 0 if relation.limit_value == 0
query_builder = build_count_subquery(relation, column_name, distinct)
+ bind_values = relation.bind_values
else
column = aggregate_column(column_name)
@@ -249,9 +252,10 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
relation.select_values = [select_value]
query_builder = relation.arel
+ bind_values = query_builder.bind_values + relation.bind_values
end
- result = @klass.connection.select_all(query_builder, nil, relation.bind_values)
+ result = @klass.connection.select_all(query_builder, nil, bind_values)
row = result.first
value = row && row.values.first
column = result.column_types.fetch(column_alias) do
View
3  activerecord/lib/active_record/relation/finder_methods.rb
@@ -255,7 +255,8 @@ def find_with_associations
if ActiveRecord::NullRelation === relation
[]
else
- rows = connection.select_all(relation.arel, 'SQL', relation.bind_values.dup)
+ arel = relation.arel
+ rows = connection.select_all(arel, 'SQL', arel.bind_values + relation.bind_values)
join_dependency.instantiate(rows, aliases)
end
end
View
2  activerecord/lib/active_record/relation/query_methods.rb
@@ -1010,7 +1010,7 @@ def build_joins(manager, joins)
join_infos.each do |info|
info.joins.each { |join| manager.from(join) }
- self.bind_values += info.binds
+ manager.bind_values.concat info.binds
end
manager.join_sources.concat(join_list)
Please sign in to comment.
Something went wrong with that request. Please try again.