title: Rails: delete cascade vs dependent destroy
body: <p>Assuming I have two tables: <code>users</code> and <code>orders</code>. A user has many orders, so naturally there is a foreign key user_id in my orders table.</p>
  
  <p>What is the best practice in rails (in terms of speed, style and referential integrity) to ensure that if a user is deleted, all dependent orders are also deleted? I am considering the following options:</p>
  
  <p>Case 1. Using <code>:dependent =&gt; :destroy</code> in the user model</p>
  
  <p>Case 2. Defining the table orders in postgres and writing</p>
  
  <pre><code>user_id integer REFERENCES users(id) ON DELETE CASCADE
  </code></pre>
  
  <p>Is there any reason why I should use Case 1? It seems that Case 2 is doing all I want it to do? Is there are difference in terms of execution speed?</p>