title: Mongoid: 2 models with a has_many and has_one relation to a third, sequence of execution seems to make a difference
body: <pre><code>class Store
    include Mongoid::Document
  
    has_many :products
    attr_readonly :products
  
    def add_product section
      product = Product.new
      section.product = desk
      self.products &lt;&lt;= desk
    end
  end
  
  class Section
    include Mongoid::Document
  
    has_one :product
  end
  </code></pre>
  
  <p>The above code doesn't quite work and the products array is never populated. However, if I simply switched the lines in the add_product method so that it looks like below, things appear to work fine:</p>
  
  <pre><code>    self.products &lt;&lt;= desk
      section.product = desk
  </code></pre>
  
  <p>I tried cloning desk and a few other quick and dirty tricks but it didn't make any difference. I am hoping to understand this behavior.</p>