From 35d731ef0aaf1b6103121bb2c2d21f5b17c26b3c Mon Sep 17 00:00:00 2001 From: Will Bryant Date: Wed, 24 Sep 2008 17:00:35 +1200 Subject: fix eager loading's :condition sanitizing expanding against the wrong table Signed-off-by: Michael Koziarski --- activerecord/lib/active_record/association_preload.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index c60850fc77..284dc7dca0 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -96,7 +96,7 @@ module ActiveRecord options = reflection.options conditions = "t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}" - conditions << append_conditions(options, preload_options) + conditions << append_conditions(reflection, preload_options) associated_records = reflection.klass.find(:all, :conditions => [conditions, ids], :include => options[:include], @@ -233,7 +233,7 @@ module ActiveRecord end end conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}" - conditions << append_conditions(options, preload_options) + conditions << append_conditions(reflection, preload_options) associated_records = klass.find(:all, :conditions => [conditions, ids], :include => options[:include], :select => options[:select], @@ -254,7 +254,7 @@ module ActiveRecord conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(ids)}" end - conditions << append_conditions(options, preload_options) + conditions << append_conditions(reflection, preload_options) reflection.klass.find(:all, :select => (preload_options[:select] || options[:select] || "#{table_name}.*"), @@ -270,9 +270,9 @@ module ActiveRecord instance_eval("%@#{sql.gsub('@', '\@')}@") end - def append_conditions(options, preload_options) + def append_conditions(reflection, preload_options) sql = "" - sql << " AND (#{interpolate_sql_for_preload(sanitize_sql(options[:conditions]))})" if options[:conditions] + sql << " AND (#{interpolate_sql_for_preload(reflection.sanitized_conditions)})" if reflection.sanitized_conditions sql << " AND (#{sanitize_sql preload_options[:conditions]})" if preload_options[:conditions] sql end -- cgit v1.2.3