public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Updated has_and_belongs_to_many association to fix :finder_sql interpolation. 
[#848 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
aniero (author)
Sat Aug 16 12:38:01 -0700 2008
lifo (committer)
Sat Aug 16 14:23:48 -0700 2008
commit  8cfdcdb35db6e2f6fd5a72a38f4352beab148af1
tree    73ee2a1467cfa181807625b7bba10e3bec15b27b
parent  2b69a636c431d62a85b2896d87b69cb13e2b8af0
...
131
132
133
134
135
136
137
138
139
140
...
131
132
133
 
 
 
 
134
135
136
0
@@ -131,10 +131,6 @@ module ActiveRecord
0
           records.map { |record| record.quoted_id }.join(',')
0
         end
0
 
0
-        def interpolate_sql_options!(options, *keys)
0
-          keys.each { |key| options[key] &&= interpolate_sql(options[key]) }
0
-        end
0
-
0
         def interpolate_sql(sql, record = nil)
0
           @owner.send(:interpolate_sql, sql, record)
0
         end
...
70
71
72
73
74
75
76
 
77
78
79
...
70
71
72
 
 
73
 
74
75
76
77
0
@@ -70,10 +70,8 @@ module ActiveRecord
0
         end
0
 
0
         def construct_sql
0
-          interpolate_sql_options!(@reflection.options, :finder_sql)
0
-
0
           if @reflection.options[:finder_sql]
0
-            @finder_sql = @reflection.options[:finder_sql]
0
+            @finder_sql = interpolate_sql(@reflection.options[:finder_sql])
0
           else
0
             @finder_sql = "#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{owner_quoted_id} "
0
             @finder_sql << " AND (#{conditions})" if conditions
...
450
451
452
 
 
 
 
 
 
 
453
454
455
...
450
451
452
453
454
455
456
457
458
459
460
461
462
0
@@ -450,6 +450,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
0
     assert_equal developers(:david), active_record.developers_with_finder_sql.find(developers(:david).id), "Ruby find"
0
   end
0
 
0
+  def test_find_in_association_with_custom_finder_sql_and_multiple_interpolations
0
+    # interpolate once:
0
+    assert_equal [developers(:david), developers(:poor_jamis), developers(:jamis)], projects(:active_record).developers_with_finder_sql, "first interpolation"
0
+    # interpolate again, for a different project id
0
+    assert_equal [developers(:david)], projects(:action_controller).developers_with_finder_sql, "second interpolation"
0
+  end
0
+
0
   def test_find_in_association_with_custom_finder_sql_and_string_id
0
     assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id.to_s), "SQL find"
0
   end

Comments