title: Cascade delete in Ruby ActiveRecord models?
body: <p>I was following the screencast on rubyonrails.org (creating the blog).</p>
  
  <p>I have following models:</p>
  
  <p>comment.rb</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
      belongs_to :post
      validates_presence_of :body # I added this
  end
  </code></pre>
  
  <p>post.rb</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
      validates_presence_of :body, :title
      has_many :comments
  end
  </code></pre>
  
  <p>Relations between models work fine, except for one thing - when I delete a post record, I'd expect RoR to delete all related comment records. I understand that ActiveRecords is database independent, so there's no built-in way to create foreign key, relations, ON DELETE, ON UPDATE statements. So, is there any way to accomplish this (maybe RoR itself could take care of deleting related comments? )?</p>