Skip to content

Commit

Permalink
Updated has_and_belongs_to_many association to fix :finder_sql interp…
Browse files Browse the repository at this point in the history
…olation. [#848 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
zerowidth authored and tarmo committed Aug 24, 2008
1 parent fcc5a6e commit 4c071bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -131,10 +131,6 @@ def quoted_record_ids(records)
records.map { |record| record.quoted_id }.join(',')
end

def interpolate_sql_options!(options, *keys)
keys.each { |key| options[key] &&= interpolate_sql(options[key]) }
end

def interpolate_sql(sql, record = nil)
@owner.send(:interpolate_sql, sql, record)
end
Expand Down
Expand Up @@ -70,10 +70,8 @@ def delete_records(records)
end

def construct_sql
interpolate_sql_options!(@reflection.options, :finder_sql)

if @reflection.options[:finder_sql]
@finder_sql = @reflection.options[:finder_sql]
@finder_sql = interpolate_sql(@reflection.options[:finder_sql])
else
@finder_sql = "#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{@owner.quoted_id} "
@finder_sql << " AND (#{conditions})" if conditions
Expand Down
Expand Up @@ -450,6 +450,13 @@ def test_find_in_association_with_custom_finder_sql
assert_equal developers(:david), active_record.developers_with_finder_sql.find(developers(:david).id), "Ruby find"
end

def test_find_in_association_with_custom_finder_sql_and_multiple_interpolations
# interpolate once:
assert_equal [developers(:david), developers(:poor_jamis), developers(:jamis)], projects(:active_record).developers_with_finder_sql, "first interpolation"
# interpolate again, for a different project id
assert_equal [developers(:david)], projects(:action_controller).developers_with_finder_sql, "second interpolation"
end

def test_find_in_association_with_custom_finder_sql_and_string_id
assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id.to_s), "SQL find"
end
Expand Down

0 comments on commit 4c071bc

Please sign in to comment.