I am playing around with relationships at the moment and am hitting a wall. I have a group. class Group < ActiveRecord::Base has_many :contacts end and a contact. class Contact < ActiveRecord::Base belongs_to :group end If I destroy group it doesn''t destroy contacts in the group. Am I missing something obvious? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
To delete contacts when the group is deleted: has_many :contacts, :dependent => :destroy or if you don''t use callbacks (before_destroy, after_destroy) in Contact, this is faster: has_many :contacts, :dependent => :delete_all chalkers wrote:> I am playing around with relationships at the moment and am hitting a > wall. > > > I have a group. > > class Group < ActiveRecord::Base > has_many :contacts > end > > and a contact. > > class Contact < ActiveRecord::Base > belongs_to :group > end > > If I destroy group it doesn''t destroy contacts in the group. > > Am I missing something obvious? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks lx Quic! Very informative. On May 18, 2:15 am, Ix Quic <ixquic696...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> To delete contacts when the group is deleted: > > has_many :contacts, :dependent => :destroy > > or if you don''t use callbacks (before_destroy, after_destroy) in Contact, > this is faster: > > has_many :contacts, :dependent => :delete_all > > chalkerswrote: > > I am playing around with relationships at the moment and am hitting a > > wall. > > > I have a group. > > > class Group < ActiveRecord::Base > > has_many :contacts > > end > > > and a contact. > > > class Contact < ActiveRecord::Base > > belongs_to :group > > end > > > If I destroy group it doesn''t destroy contacts in the group. > > > Am I missing something obvious? > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---