I''m a newb with a quick question. I have a model class Call has_many :visits and class Visit belongs_to :call If I delete a call will it automatically delete the associated visits?? Any help will be greatly appreciated --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 5, 2008, at 5:22 PM, THEBIGO wrote:> > I''m a newb with a quick question. > > I have a model > class Call > has_many :visitshas_many :visits, :dependent => :destroy this should do the trick. Best. Mike> > and > class Visit > belongs_to :call > > If I delete a call will it automatically delete the associated > visits?? > Any help will be greatly appreciated > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 5, 2008, at 5:22 PM, THEBIGO wrote:> > I''m a newb with a quick question. > > I have a model > class Call > has_many :visits > and > class Visit > belongs_to :call > > If I delete a call will it automatically delete the associated > visits??Sorry, I was too quick on the draw with the last email. The association you have will not delete the visits. The last message I posted will destroy associated visits when you destroy the call. If you don''t want AR callbacks to fire on the associated vists you can use has_many :visits, :dependent => :delete_all Best. Mike> > Any help will be greatly appreciated > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike - Thank you for your response so I take it that if I have say 20 calls and call with call.id = 5 and if there are say 11 visits with various visit.id''s but with their call_id = 5 linking them to the above call then when I execute the delete action for call with id=5 then it will be deleted along with it''s 11 visits then I should use the first one you said has_many :visits, :dependent => :destroy ???? Thanks again On Jul 5, 3:24 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 5, 2008, at 5:22 PM, THEBIGO wrote: > > > > > I''m a newb with a quick question. > > > I have amodel > > class Call > > has_many :visits > > and > > class Visit > > belongs_to :call > > > If Ideletea call will it automaticallydeletethe associated > > visits?? > > Sorry, I was too quick on the draw with the last email. > > The association you have will notdeletethe visits. The last message > I posted will destroy associated visits when you destroy the call. > > If you don''t want AR callbacks to fire on the associated vists you can > use has_many :visits, :dependent => :delete_all > > Best. > Mike > > > > > Any help will be greatly appreciated--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 5, 2008, at 6:37 PM, THEBIGO wrote:> > Mike - Thank you for your response so I take it that if I have say 20 > calls and call with call.id = 5 and if > there are say 11 visits with various visit.id''s but with their call_id > = 5 linking them to the above call > then when I execute the delete action for call with id=5 then it will > be deleted along with it''s 11 visits > then I should use the first one you said > > has_many :visits, :dependent => :destroy ????From the API http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html : dependent - If set to :destroy all the associated objects are destroyed alongside this object by calling their destroy method. If set to :delete_all all associated objects are deleted without calling their destroy method. If set to :nullify all associated objects’ foreign keys are set to NULL without calling their save callbacks. *Warning:* This option is ignored when also using the :through option. Best. Mike> > > Thanks again > > On Jul 5, 3:24 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Jul 5, 2008, at 5:22 PM, THEBIGO wrote: >> >> >> >>> I''m a newb with a quick question. >> >>> I have amodel >>> class Call >>> has_many :visits >>> and >>> class Visit >>> belongs_to :call >> >>> If Ideletea call will it automaticallydeletethe associated >>> visits?? >> >> Sorry, I was too quick on the draw with the last email. >> >> The association you have will notdeletethe visits. The last message >> I posted will destroy associated visits when you destroy the call. >> >> If you don''t want AR callbacks to fire on the associated vists you >> can >> use has_many :visits, :dependent => :delete_all >> >> Best. >> Mike >> >> >> >>> Any help will be greatly appreciated > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you mike so very much - it worked like a charm. One more itteration complete Owen On Jul 5, 3:43 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 5, 2008, at 6:37 PM, THEBIGO wrote: > > > > > Mike - Thank you for your response so I take it that if I have say 20 > > calls and call with call.id = 5 and if > > there are say 11 visits with various visit.id''s but with their call_id > > = 5 linking them to the above call > > then when I execute thedeleteaction for call with id=5 then it will > > be deleted along with it''s 11 visits > > then I should use the first one you said > > > has_many :visits, :dependent => :destroy ???? > > From the APIhttp://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet... > : > > dependent - If set to :destroy all the associated objects are > destroyed alongside this object by calling their destroy method. If > set to :delete_all all associated objects are deleted without calling > their destroy method. If set to :nullify all associated objects’ > foreign keys are set to NULL without calling their save callbacks. > *Warning:* This option is ignored when also using the :through option. > > Best. > Mike > > > > > Thanks again > > > On Jul 5, 3:24 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Jul 5, 2008, at 5:22 PM, THEBIGO wrote: > > >>> I''m a newb with a quick question. > > >>> I have amodel > >>> class Call > >>> has_many :visits > >>> and > >>> class Visit > >>> belongs_to :call > > >>> If Ideletea call will it automaticallydeletethe associated > >>> visits?? > > >> Sorry, I was too quick on the draw with the last email. > > >> The association you have will notdeletethe visits. The last message > >> I posted will destroy associated visits when you destroy the call. > > >> If you don''t want AR callbacks to fire on the associated vists you > >> can > >> use has_many :visits, :dependent => :delete_all > > >> Best. > >> Mike > > >>> Any help will be greatly appreciated--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---