This project is archived and is in readonly mode.
has_one :through on new record doesn't query for associated object
Reported by Alexey Ilyichev | October 22nd, 2010 @ 03:12 PM
Given:
class User < AR
has_one :user_info
has_many :bank_infos
end
class UserInfo < AR
belongs_to :user
end
class BankInfo < AR
belongs_to :user
has_one :user_info, :through => :user
end
I do:
bank_info = user.bank_infos.build
bank_info.user_info
where user has associated user_info. And I expect bank_info.user_info to equal user.user_info, however it is nil.
Attaching patch...
Any feedback would be appreciated.
Comments and changes to this ticket
-
Alexey Ilyichev October 22nd, 2010 @ 04:24 PM
Sorry for weird formatting. Code from previous post
class User < AR has_one :user_info has_many :bank_infos end
class UserInfo < AR belongs_to :user end
class BankInfo < AR belongs_to :user has_one :user_info, :through => :user end -
Jon Leighton December 21st, 2010 @ 07:57 PM
- State changed from new to invalid
- Importance changed from to Low
Hi there,
Thanks for the bug report. To do this you can use the
:inverse_of
option on yourUser.has_many :bank_infos
.Jon
-
Alexey Ilyichev January 19th, 2011 @ 02:13 PM
Hi, Jon.
Thanks for the reply. Inverse_of does not solve anything in this case.
-
Jon Leighton January 23rd, 2011 @ 09:41 PM
Hi,
You're right, inverse_of is irrelevant here. However I have just tried the test case you provided against latest master and it passes.
Thanks
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>