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>
[#1101 state:commited]
Will Bryant (author)
Tue Sep 23 22:00:35 -0700 2008
NZKoz (committer)
Mon Sep 29 08:50:26 -0700 2008
commit  7823c50c975df975ca3237bfbe9ca0b3c60f6b6d
tree    4b8f745b5e31439bd745a5a7547df1f330827212
parent  e34e6d67e3861dab5b6e21703c0fefa96e728158
...
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
...
112
113
114
 
 
 
 
115
116
117
...
112
113
114
115
116
117
118
119
120
121
0
@@ -112,6 +112,10 @@ module ActiveRecord
0
         name == other_aggregation.name && other_aggregation.options && active_record == other_aggregation.active_record
0
       end
0
 
0
+      def sanitized_conditions #:nodoc:
0
+        @sanitized_conditions ||= klass.send(:sanitize_sql, options[:conditions]) if options[:conditions]
0
+      end
0
+
0
       private
0
         def derive_class_name
0
           name.to_s.camelize

Comments