title: Rails has_one :through. Building associated object
body: <p>I have the following data model in my Rails 2.3 application</p>
  
  <pre><code>class PortraitSubject
    has_many    :portraits
    has_one     :primary_portrait, :through =&gt; :portraits, :source =&gt; :asset, :conditions =&gt; ['portraits.primary = ?', true]
    has_many    :supplementary_portraits, :through =&gt; :portraits, :source =&gt; :asset, :conditions =&gt; ['portraits.primary = ?', false]
  
    ...
  end
  
  class Portrait
    belongs_to :portrait_subject
    belongs_to :asset
  
    ...
  end
  </code></pre>
  
  <p>I want to build the associated proxy models using Rails but trying to build <code>primary_portrait</code> fails with an exception. I.e.</p>
  
  <pre><code># This works
  subject = PortraitSubject.new
  subject.supplementary_portraits.build
  subject.save
  
  # This doesn't
  subject = PortraitSubject.new
  subject.build_primary_portrait
  # =&gt; NoMethodError: undefined method `build_primary_portrait' for #&lt;PortraitSubject:0x007ff16fe38948&gt;
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong. Looking through the Rails guides it looks like this should be possible with a <code>has_one</code> relationship. Any help would be greatly appreciated.</p>