This project is archived and is in readonly mode.
preloading has_one :through on a belongs_to
Reported by Matt Jones | December 2nd, 2008 @ 09:40 PM
Preloading a has_one :through on a belongs_to finds the records but doesn't correctly set the association.
An example (abbreviated from the tests):
class Member < ActiveRecord::Base
belongs_to :member_type
end
class MemberDetail < ActiveRecord::Base
belongs_to :member
has_one :member_type, :through => :member
end
class MemberType < ActiveRecord::Base
has_many :members # not relevant here
end
This case is supported in the regular association code, but doing
MemberDetail.find(:all, :include => :member_type)
leaves all the result records with member_type nil, but loaded_member_type? true.
The attached patch fixes this, and includes a test for this case.
It also includes a (tiny) fix for AssociationCollection#to_ary, where has_one :through associations would give an error (trying to call to_ary on a lone AR object).
Comments and changes to this ticket
-
David Stevenson December 6th, 2008 @ 02:47 AM
- toary has Bren driving me crazy! Can't include past a has one thru cause of it!
-
Pratik December 7th, 2008 @ 04:00 AM
- Assigned user set to Pratik
-
Michael Koziarski December 10th, 2008 @ 06:53 PM
- Milestone cleared.
-
Pratik December 10th, 2008 @ 07:17 PM
- Assigned user changed from Pratik to Frederick Cheung
Fred : Looks good ?
-
Frederick Cheung December 10th, 2008 @ 09:57 PM
- Assigned user changed from Frederick Cheung to Pratik
Looks sane to me
-
Repository December 18th, 2008 @ 07:22 PM
- State changed from new to resolved
(from [a9422cc1db9501a80ecf2c25a5d3b0c4f4f32763]) Fix preloading of has_one :through associations on belongs_to [#1507 state:resolved]
Signed-off-by: Frederick Cheung frederick.cheung@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
Referenced by
- 1507 preloading has_one :through on a belongs_to (from [a9422cc1db9501a80ecf2c25a5d3b0c4f4f32763]) Fix pre...