title: Rails STI build relation
body: <p>I'm using STI (correctly, I promise!) for one relation of an object:</p>
  
  <pre><code>class Walrus &lt; ActiveRecord::Base
    has_one :bubbles
  end
  
  class Bubbles &lt; ActiveRecord::Base
    belongs_to :walrus
    before_save :set_origin
  
    private
  
    def set_origin
      self.type = walrus.state ? "Bubbles::#{walrus.state}" : 'Bubbles'
    end
  end
  
  class Bubbles::OfMind &lt; Bubbles
    def tango
    end
  end
  </code></pre>
  
  <p>Now if I build a new relation, the class isn't set correctly:</p>
  
  <pre><code>harold = Walrus.new(state: 'OfMind')
  harold.build_bubbles.save!
  harold.bubbles
    # =&gt; returns instance of Bubbles, not Bubbles::OfMind
  harold.bubbles.tango
    # NoMethodError
  </code></pre>
  
  <p>The Bubbles object cannot magically become a Bubbles::OfMind, but until the relation is of the correct type, the correct functionality does not exist.</p>