title: Nested models and parent validation
body: <p>I've got two models. <br />
  - <code>Parent</code> <strong>has_many</strong> <code>Children</code>;<br />
  - <code>Parent</code> <strong>accepts_nested_attributes_for</strong> <code>Children</code>;</p>
  
  <pre><code>class Parent &lt; ActiveRecord::Base
    has_many :children, :dependent =&gt; :destroy
    accepts_nested_attributes_for :children, :allow_destroy =&gt; true
    validates :children, :presence =&gt; true
  end
  
  class Child &lt; ActiveRecord::Base
    belongs_to :parent
  end
  </code></pre>
  
  <p>I use validation to validate presence of children for every parent, so I can't save parent without children.</p>
  
  <pre><code>parent = Parent.new :name =&gt; "Jose"
  parent.save
  #=&gt; false
  parent.children_attributes = [{:name =&gt; "Pedro"}, {:name =&gt; "Emmy"}]
  parent.save
  #=&gt; true
  </code></pre>
  
  <p>validation works. Then we will destroy children via <code>_destroy</code> attribute:</p>
  
  <pre><code>parent.children_attributes = {"0" =&gt; {:id =&gt; 0, :_destroy =&gt; true}}
  parent.save
  #=&gt; true !!!
  parent.reload.children
  #=&gt; []
  </code></pre>
  
  <p>so I can destroy all children via nested forms and validation will pass.</p>
  
  <p>Actually that happens because after I delete child from my parent via <code>_delete</code>, children method still returns destroyed object before I reload it, so validation passed:</p>
  
  <pre><code>parent.children_attributes = {"0" =&gt; {:id =&gt; 0, :_destroy =&gt; true}}
  parent.save
  #=&gt; true !!!
  parent.children
  #=&gt; #&lt;Child id:1 ...&gt; # It's actually deleted
  parent.reload.children
  #=&gt; []
  </code></pre>
  
  <p>Is it bug?</p>
  
  <p>What is the question. The question is best solution to repair it. My approach is to add before_destroy filter to <code>Child</code> to check if it is last one. But it makes system complicated.</p>