Rails cascading delete

Hello There:     I am trying to do a deep cascading deletes in rails.

The schema looks like this:

Blogs (has many) entries ( has many ) comments

A blog has n entries, an entry has n comments.

So, in my Blog model I use has_many :entries, :dependent => :delete_all and in my Entry model I use has_many :comments,:dependent => :delete_all

   The problem I am having is that deleting blogs, will only delete entries, but will not delete comments. In other words, the cascading delete isn't deep?

   Am I doing something wrong here?

Thanks Hilal

Try:

:dependent => :destroy

Hi Hilal,

You need to use :dependent => :destroy instead of :delete_all because :delete_all doesn’t fire any callbacks. That’s why it only deletes one level.

/Lasse

Thanks all. Destroy worked great!,

Thanks Hila;