public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
fix eager loading's :condition sanitizing expanding against the wrong table

Signed-off-by: Michael Koziarski <michael@koziarski.com>
Will Bryant (author)
Tue Sep 23 22:00:35 -0700 2008
NZKoz (committer)
Mon Sep 29 08:49:44 -0700 2008
commit  35d731ef0aaf1b6103121bb2c2d21f5b17c26b3c
tree    16b8c952117f2bf75e78a97a9dd00ad2bc4cf873
parent  8233f8314ba00838e8ef6b2d95cdfb7d58c8dece
...
96
97
98
99
 
100
101
102
...
233
234
235
236
 
237
238
239
...
254
255
256
257
 
258
259
260
...
270
271
272
273
 
274
275
 
276
277
278
...
96
97
98
 
99
100
101
102
...
233
234
235
 
236
237
238
239
...
254
255
256
 
257
258
259
260
...
270
271
272
 
273
274
 
275
276
277
278
0
@@ -96,7 +96,7 @@ module ActiveRecord
0
         options = reflection.options
0
 
0
         conditions = "t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}"
0
-        conditions << append_conditions(options, preload_options)
0
+        conditions << append_conditions(reflection, preload_options)
0
 
0
         associated_records = reflection.klass.find(:all, :conditions => [conditions, ids],
0
         :include => options[:include],
0
@@ -233,7 +233,7 @@ module ActiveRecord
0
             end
0
           end
0
           conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}"
0
-          conditions << append_conditions(options, preload_options)
0
+          conditions << append_conditions(reflection, preload_options)
0
           associated_records = klass.find(:all, :conditions => [conditions, ids],
0
                                           :include => options[:include],
0
                                           :select => options[:select],
0
@@ -254,7 +254,7 @@ module ActiveRecord
0
           conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(ids)}"
0
         end
0
 
0
-        conditions << append_conditions(options, preload_options)
0
+        conditions << append_conditions(reflection, preload_options)
0
 
0
         reflection.klass.find(:all,
0
                               :select => (preload_options[:select] || options[:select] || "#{table_name}.*"),
0
@@ -270,9 +270,9 @@ module ActiveRecord
0
         instance_eval("%@#{sql.gsub('@', '\@')}@")
0
       end
0
 
0
-      def append_conditions(options, preload_options)
0
+      def append_conditions(reflection, preload_options)
0
         sql = ""
0
-        sql << " AND (#{interpolate_sql_for_preload(sanitize_sql(options[:conditions]))})" if options[:conditions]
0
+        sql << " AND (#{interpolate_sql_for_preload(reflection.sanitized_conditions)})" if reflection.sanitized_conditions
0
         sql << " AND (#{sanitize_sql preload_options[:conditions]})" if preload_options[:conditions]
0
         sql
0
       end

Comments