This project is archived and is in readonly mode.
has_one through doesn't work on new record
Reported by Tatsuya Ono | July 21st, 2010 @ 09:27 AM
Here is example:
class Organization < ActiveRecord::Base
has_many :members
end
class Member < ActiveRecord::Base
has_one :organization # or belongs_to
end
class MemberHouse < ActiveRecord::Base
has_one :member # or belongs_to
has_one :organization, :through => :member
end
Then...
@organization = Organization.last
@member = @organiation.members.last
@member_house = MemberHouse.new(:address => "87 Worship Street")
@member_house.member = @member
In this situation, I expect that @member_house.organization returns @organization; but it returns nil actually.
Comments and changes to this ticket
-
Jigar Patel July 24th, 2010 @ 11:50 AM
You are not saving the @member_house object. Save it and then assign a member to it. You can fetch organization after that.
Close the ticket since this is a coding issue and not a bug.
-
Jigar Patel July 24th, 2010 @ 08:01 PM
- Assigned user set to Pratik
- Tag changed from 3.x to 3.x, invalid
-
Neeraj Singh July 26th, 2010 @ 08:37 PM
- State changed from new to invalid
- Importance changed from to Low
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>