Christopher J. Bottaro
2008-Mar-11 23:43 UTC
saving an ActiveRecord without trigging the callbacks
Hello, How can I save an ActiveRecord without trigger before_save, after_save, etc? Thanks for the help. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can skip callbacks while deleting records but I don''t think you can while saving them, hence you have to rely on raw SQL instead of RoR AR / ORM. Check this out, you might get some idea from it nasir.wordpress.com/2007/12/03/stored-procedures-and-rails On Mar 11, 11:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > How can I save an ActiveRecord without trigger before_save, > after_save, etc? > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It depends on the type of update you want to do. If you only need to update a single parameter or two then you can use update_attribute (note: singular). As the name suggests it accepts a single attribute name and the corresponding value. If you need to do more than that then you may want to reconsider what your callbacks are doing. At the very least you could add conditions to the top of the callback that causes them to shortcircuit. On Mar 11, 7:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > How can I save an ActiveRecord without trigger before_save, > after_save, etc? > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christopher J. Bottaro
2008-Mar-12 21:39 UTC
Re: saving an ActiveRecord without trigging the callbacks
Excellent, thanks. I am just updating a single field. On Mar 12, 11:18 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> It depends on the type of update you want to do. If you only need to > update a single parameter or two then you can use update_attribute > (note: singular). As the name suggests it accepts a single attribute > name and the corresponding value. > > If you need to do more than that then you may want to reconsider what > your callbacks are doing. At the very least you could add conditions > to the top of the callback that causes them to shortcircuit. > > On Mar 11, 7:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Hello, > > How can I save an ActiveRecord without trigger before_save, > > after_save, etc? > > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christopher J. Bottaro
2008-Mar-12 21:47 UTC
Re: saving an ActiveRecord without trigging the callbacks
Oops, spoke too soon. ActiveRecord::Base#update_attribute does indeed trigger the before/after save callbacks. I don''t think it triggers validation though. -- C On Mar 12, 4:39 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Excellent, thanks. I am just updating a single field. > > On Mar 12, 11:18 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > It depends on the type of update you want to do. If you only need to > > update a single parameter or two then you can use update_attribute > > (note: singular). As the name suggests it accepts a single attribute > > name and the corresponding value. > > > If you need to do more than that then you may want to reconsider what > > your callbacks are doing. At the very least you could add conditions > > to the top of the callback that causes them to shortcircuit. > > > On Mar 11, 7:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > Hello, > > > How can I save an ActiveRecord without trigger before_save, > > > after_save, etc? > > > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok.. so no answers to this one? I understand find_by_sql... whats the update_by_sql alternative? On Mar 12, 2:47 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oops, spoke too soon. ActiveRecord::Base#update_attribute does indeed > trigger the before/after save callbacks. I don''t think it triggers > validation though. > > -- C > > On Mar 12, 4:39 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Excellent, thanks. I am just updating a single field. > > > On Mar 12, 11:18 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > > It depends on the type of update you want to do. If you only need to > > > update a single parameter or two then you can use update_attribute > > > (note: singular). As the name suggests it accepts a single attribute > > > name and the corresponding value. > > > > If you need to do more than that then you may want to reconsider what > > > your callbacks are doing. At the very least you could add conditions > > > to the top of the callback that causes them to shortcircuit. > > > > On Mar 11, 7:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > Hello, > > > > How can I save an ActiveRecord without trigger before_save, > > > > after_save, etc? > > > > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Julian Leviston
2008-Apr-02 06:57 UTC
Re: saving an ActiveRecord without trigging the callbacks
You can put whatever SQL you like in find_by_sql, I think. Therefore, you can put an update, or delete or anything in there. Hope that helps. Julian. Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO OUT 3rd APRIL sensei.zenunit.com On 02/04/2008, at 5:13 PM, jacques wrote:> > Ok.. so no answers to this one? > > I understand find_by_sql... whats the update_by_sql alternative? > > On Mar 12, 2:47 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> Oops, spoke too soon. ActiveRecord::Base#update_attribute does >> indeed >> trigger the before/after save callbacks. I don''t think it triggers >> validation though. >> >> -- C >> >> On Mar 12, 4:39 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> >>> Excellent, thanks. I am just updating a single field. >> >>> On Mar 12, 11:18 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: >> >>>> It depends on the type of update you want to do. If you only >>>> need to >>>> update a single parameter or two then you can use update_attribute >>>> (note: singular). As the name suggests it accepts a single >>>> attribute >>>> name and the corresponding value. >> >>>> If you need to do more than that then you may want to reconsider >>>> what >>>> your callbacks are doing. At the very least you could add >>>> conditions >>>> to the top of the callback that causes them to shortcircuit. >> >>>> On Mar 11, 7:43 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>> wrote: >> >>>>> Hello, >>>>> How can I save an ActiveRecord without trigger before_save, >>>>> after_save, etc? >> >>>>> Thanks for the help. > >--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Keeping attributes of two models in sync
- Paperclip not executing FFMPEG properly
- Update attribute without validations or any save hooks?
- Event Calendar/Scheduler Implementation
- Suggestion: `before_save on: :create` should either work or raise an exception