If a class defines a HABTM association using :finder_sql, the finder_sql statement is only interpolated once. Subsequent calls to the association execute the identical SQL statement.
For example, say you have classes like:
class Category < ActiveRecord::Base
has_and_belongs_to_many :items, :finder_sql => '
SELECT i.*
FROM items i INNER JOIN category_item_map m ON m.item_id = i.id
WHERE m.category_id = #{id}'
end
class Item < ActiveRecord::Base
end
You retrieve a list of categories, and want to iterate over the items association for each category in your list. When the finder_sql is interpolated the first time, the "#{id}" will be replaced by the id of the current category model. Subsequent SQL calls will use the same statement--id will still be for the first category.
This applies to edge and stable.