title: What Does Rails Do With Both :dependent => :destroy and cascade delete/nullify/restrict
body: <p>I'm trying to decide how best to set up (if at all) foreign key constraints for my rails application.  I have a model <code>Response</code> that <code>belongs_to</code> a <code>Prompt</code>.  I would like to use <code>:dependent =&gt; :destroy</code> to have  destroy called on every <code>Response</code> that belongs to a deleted <code>Prompt</code> and I'm trying to decide what delete constraint I should place on my foreign key.</p>
  
  <p>In short I want advice about how I can get best take advantage of both the destroy method on dependent objects and foreign key constraints to ensure cruft doesn't accumulate and reflect the logical structure of the data being stored.  Several earlier questions such as <a href="https://stackoverflow.com/questions/1189970/should-i-use-on-delete-cascade-dependent-destroy-or-both">Should I use ON DELETE CASCADE, :dependent =&gt; :destroy, or both?</a> and <a href="https://stackoverflow.com/questions/12556614/rails-delete-cascade-vs-dependent-destroy?rq=1">Rails: delete cascade vs dependent destroy</a> asked which was better but they don't really say much about how the two choices interact and in what order they are triggered or seemed vague on the point.</p>
  
  <p>As I see it the considerations seem to break up into a few pieces:</p>
  
  <ol>
  <li>Does <code>:dependent =&gt; :destroy</code> call destroy first on the dependent objects before removing the parent from the database so destroy will still be called on these objects even if I use cascade delete?</li>
  <li><p>Does <code>:dependent =&gt; :destroy</code> remove the dependent objects from the database before (or in a transaction with) removing the parent from the database?  In other words if I set cascade to nullify will the database end up wastefully nullifying the references on the child objects before they are deleted?</p></li>
  <li><p>Are deletes issued as a result of the original destroy and chained <code>:dependent =&gt; :destroy</code> options wrapped in a transaction or will unfortunately timed crashes leave cruft in the database if I don't set cascade delete?</p></li>
  <li>Finally will <code>:dependent =&gt; :destroy</code> ensure the parent object is deleted from the database if I use restrict as the foreign key on_delete option?</li>
  </ol>