# Has\_one through with new record

**URL:** <https://www.ruby-forum.com/t/has-one-through-with-new-record/160675>\
**Category:** Rails\
**Created:** [February 18, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/has-one-through-with-new-record/160675 "2009-02-18T18:49:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias\_Schneider](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tobias\_Schneider](https://www.ruby-forum.com/u/Tobias_Schneider)\
**Post date:** [February 18, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/has-one-through-with-new-record/160675/1 "2009-02-18T18:49:02Z")

</div>

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?
