From eb2bb7d56f1eefb96a99321b18ed7b4b7ef1d4d6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 17:20:20 -0700 Subject: push binds through relation objects --- activerecord/lib/active_record/associations/association_scope.rb | 1 + .../active_record/associations/join_dependency/join_association.rb | 4 +++- activerecord/lib/active_record/associations/preloader/association.rb | 3 +++ activerecord/lib/active_record/relation/query_methods.rb | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index aa5551fe0c..21840ba74a 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -101,6 +101,7 @@ module ActiveRecord scope.includes! item.includes_values scope.where_values += item.where_values + scope.bind_values += item.bind_values scope.order_values |= item.order_values end end diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index b81aecb4e5..33b363339c 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -64,7 +64,7 @@ module ActiveRecord end end - def join_to(manager) + def join_to(manager, relation) tables = @tables.dup foreign_table = parent_table foreign_klass = parent.base_klass @@ -111,6 +111,8 @@ module ActiveRecord item = ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item) end + relation.bind_values += item.bind_values + if item.arel.constraints.empty? chain else diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 82588905c6..f55b4824e5 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -101,10 +101,13 @@ module ActiveRecord scope.default_scoped = true values = reflection_scope.values + reflection_binds = reflection_scope.bind_values preload_values = preload_scope.values + preload_binds = preload_scope.bind_values scope.where_values = Array(values[:where]) + Array(preload_values[:where]) scope.references_values = Array(values[:references]) + Array(preload_values[:references]) + scope.bind_values = (reflection_binds + preload_binds) scope.select! preload_values[:select] || values[:select] || table[Arel.star] scope.includes! preload_values[:includes] || values[:includes] diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 4628a5811b..c27afb512f 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -982,7 +982,7 @@ module ActiveRecord # FIXME: refactor this to build an AST join_dependency.join_associations.each do |association| - association.join_to(manager) + association.join_to(manager, self) end manager.join_sources.concat join_list -- cgit v1.2.3