This project is archived and is in readonly mode.
finder_sql in has_and_belongs_to_many is only interpolated once
Reported by Nathan Witmer | August 16th, 2008 @ 08:44 PM | in 2.x
class Project < ActiveRecord::Base
has_and_belongs_to_many :developers, :finder_sql => 'select d.* from developers d inner join developers_projects dp on d.id = dp.developer_id where dp.project_id = #{id}'
end
class Developer < ActiveRecord::Base
end
Given two projects and a few developers, say, project 1 has a, b, c, and project 2 has d and e:
# interpolates the SQL for project id 1
Project.find(1).developers # => [a, b, c]
# but now it's been permanently altered:
Project.find(2).developers # => [a, b, c], should be [d, e]
The problem is in the habtm construct_sql
method, which replaces the reflection's :finder_sql
option with the interpolated version. Instead, this should be recalculated every time the habtm association is instantiated.
I have attached a test case and the patch to fix this bug.
Comments and changes to this ticket
-
Nathan Witmer August 16th, 2008 @ 08:49 PM
I should note that removing
interpolate_sql_options!
doesn't affect anything else, it was only being used in the habtm association. -
Repository August 16th, 2008 @ 10:25 PM
- State changed from new to resolved
(from [8cfdcdb35db6e2f6fd5a72a38f4352beab148af1]) Updated has_and_belongs_to_many association to fix :finder_sql interpolation. [#848 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Repository August 25th, 2008 @ 09:30 AM
(from [4c071bc796e07e33497937bdc92d3d8d3ef365f1]) Updated has_and_belongs_to_many association to fix :finder_sql interpolation. [#848 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 848 finder_sql in has_and_belongs_to_many is only interpolated once (from [8cfdcdb35db6e2f6fd5a72a38f4352beab148af1]) Updated...
- 848 finder_sql in has_and_belongs_to_many is only interpolated once (from [4c071bc796e07e33497937bdc92d3d8d3ef365f1]) Updated...