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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 April 2010 08:08, Hilal <hilal.shaath-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello There: > I am trying to do a deep cascading deletes in rails. > > 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?Try: :dependent => :destroy http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 2010/4/2 Hilal <hilal.shaath-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> 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 > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks all. Destroy worked great!, Thanks Hila; On Apr 2, 2:41 am, Lasse Bunk <lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > 2010/4/2 Hilal <hilal.sha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > 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 > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.