what is the difference between destroy and delete in AR I am not sure what they mean by "Destroys the record with the given id by instantiating the object and calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all the callbacks are the triggered). If an array of ids is provided, all of them are destroyed." in http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866 I am guessing destrou uses the relationships in your model file to delete the has_one and has_many relationships and delete only deletes the current object is this true? cheers dion -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/d82a06a2/attachment.html
yes this is true destroy does find all the relations...and ''destroys'' them...wooot sweet, now I love this AR stuff On 7/23/06, Dion Hewson <dionhewson@gmail.com> wrote:> > what is the difference between destroy and delete in AR > > I am not sure what they mean by > > "Destroys the record with the given id by instantiating the object and > calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all the callbacks are the triggered). If an array of ids is provided, all > of them are destroyed." > > in http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866 > > > I am guessing destrou uses the relationships in your model file to delete > the has_one and has_many relationships and delete only deletes the current > object > > is this true? > > cheers dion > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/a5b113d4/attachment.html
On 7/23/06, Dion Hewson <dionhewson@gmail.com> wrote:> > yes this is true destroy does find all the relations...and ''destroys'' > them...wooot > > sweet, now I love this AR stuff >You may need to give AR a prod if you want all relations destroyed. In your has_many/has_one/HABTM relationships you need to include :dependent => :destroy_all On 7/23/06, Dion Hewson <dionhewson@gmail.com> wrote:> > > > what is the difference between destroy and delete in AR > > > > I am not sure what they mean by > > > > "Destroys the record with the given id by instantiating the object and > > calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all the callbacks are the triggered). If an array of ids is provided, all > > of them are destroyed." > > > > in http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866 > > > > > > > > I am guessing destrou uses the relationships in your model file to > > delete the has_one and has_many relationships and delete only deletes the > > current object > > > > is this true? > > > > cheers dion > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/0676c742/attachment.html
Daniel ----- wrote:> On 7/23/06, Dion Hewson <dionhewson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> yes this is true destroy does find all the relations...and ''destroys'' >> them...wooot >> >> sweet, now I love this AR stuff >> > > You may need to give AR a prod if you want all relations destroyed. In > your > has_many/has_one/HABTM relationships you need to include :dependent => > :destroy_all:dependent => :destroy_all must be added on all of them like this? has_many :products :dependent => :destroy_all has_many :lists :dependent => :destroy_all has_many :friends :dependent => :destroy_all has_many :buytogethers :dependent => :destroy_all has_many :comments :dependent => :destroy_all Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Short answer: Yes Slightly longer answer: destroy will not automatically destroy associated records. Rather than have Rails default to destroying your data, it sensibly refrains from rampages of destruction and leaves the owner of the data to decide its fate. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Um... Care to further explain that one? I''m a little fuzzy on the long answer, which seems to me to contradict the short answer. RSL On 1/22/07, askegg <andrew.skegg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Short answer: Yes > > Slightly longer answer: destroy will not automatically destroy > associated records. Rather than have Rails default to destroying your > data, it sensibly refrains from rampages of destruction and leaves the > owner of the data to decide its fate. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Basically, when you call ''destroy'' on an object, it will not automatically remove the associated records unless you specifically ask it to in the ''has_many'' declaration. askegg''s long answer is quite poetic but a little complicated :0) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Bartholomew wrote:> Basically, when you call ''destroy'' on an object, it will not > automatically remove the associated records unless you specifically ask > it to in the ''has_many'' declaration. > > askegg''s long answer is quite poetic but a little complicated :0)What he said :) You don''t want a framework to assume you want all related data to be destroyed. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gotcha! On 1/22/07, askegg <andrew.skegg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > Steve Bartholomew wrote: > > Basically, when you call ''destroy'' on an object, it will not > > automatically remove the associated records unless you specifically ask > > it to in the ''has_many'' declaration. > > > > askegg''s long answer is quite poetic but a little complicated :0) > > What he said :) > > You don''t want a framework to assume you want all related data to be > destroyed. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---