# Saving an ActiveRecord without trigging the callbacks

**URL:** <https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625>\
**Category:** Rails\
**Created:** [March 12, 2008, 12:43am UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625 "2008-03-12T00:43:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [March 12, 2008, 12:43am UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/1 "2008-03-12T00:43:53Z")

</div>

Hello,  
How can I save an ActiveRecord without trigger before\_save,  
after\_save, etc?

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [March 12, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/2 "2008-03-12T15:54:33Z")

</div>

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

> **[Stored Procedures and Rails – Part 1](https://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/)**
>
> There is no documentation in Rails about how to use stored procedures or atleast it is difficult to find where to look at. And according to DHH stored procedures is not the Rails Way to do things. …

On Mar 11, 11:43 pm, “Christopher J. Bottaro” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [March 12, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/3 "2008-03-12T17:19:15Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [March 12, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/4 "2008-03-12T22:39:54Z")

</div>

Excellent, thanks. I am just updating a single field.

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [April 2, 2008, 8:14am UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/5 "2008-04-02T08:14:53Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [March 12, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/6 "2008-03-12T22:48:43Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [April 2, 2008, 8:58am UTC](https://www.ruby-forum.com/t/saving-an-activerecord-without-trigging-the-callbacks/131625/7 "2008-04-02T08:58:40Z")

</div>

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  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)
