Forum: Ruby on Rails has_one through with new record

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tobias Schneider (Guest)
on 2009-02-18 19:49
(Received via mailing list)
I need to set a has_one through association to an unsaved record. In
my code

  class JobPositionPosting < ActiveRecord::Base
    has_one :job_position_posting_hiring_org
    has_one :hiring_org, :through => :job_position_posting_hiring_org

  class JobPositionPostingHiringOrg < ActiveRecord::Base
    belongs_to :job_position_posting
    belongs_to :hiring_org

  class HiringOrg < ActiveRecord::Base
    has_many :job_position_posting_hiring_org
    has_many :job_position_posting, :through
=> :job_position_posting_hiring_org

  job_position_posting =
  hiring_org =

  job_position_posting.hiring_org = hiring_org

, job_position_posting.hiring_org is always set to nil. If i save
job_position_posting and hiring_org everything works fine. How can i
realize an has_one :trough with new records?
This topic is locked and can not be replied to.