Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

has_one through doesn't work on new record

#5168

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.

Reported by Tatsuya Ono · July 21st, 2010 @ 09:27 AM

State: invalid
Milestone: none
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Tatsuya Ono
  2. Subba
    Subba

    using inverse_of will fix your problem.

    July 22nd, 2010 @ 07:28 PM

  3. Jigar Patel
    Jigar Patel

    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.

    July 24th, 2010 @ 11:50 AM

  4. Jigar Patel
    Jigar Patel
    • Assigned user set to Pratik
    • Tag changed from 3.x to 3.x, invalid

    July 24th, 2010 @ 08:01 PM

  5. Neeraj Singh
    Neeraj Singh
    • State changed from new to invalid
    • Importance changed from to Low

    July 26th, 2010 @ 08:37 PM