Forum: Ruby on Rails has_one through with new record

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4c070ea4b5d033a7f5c98b08fb836a54?d=identicon&s=25 Tobias Schneider (Guest)
on 2009-02-18 18: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
  end

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

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

  job_position_posting = JobPositionPosting.new
  hiring_org = HiringOrg.new

  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.