rails/rails — pull request #4884 by patrick99e99 (2012-02-05 08:41:54+00:00)
Title: added skip_callbacks functionality to ActiveRecord's save, create, destroy, update_attributes methods

I have recently been experiencing situations where I've wanted to create or save a record and not have the model's callbacks fire. I have had to manually deal with this in my models by adding procs to the callback declarations, such as:

before_save :my_method, :unless => proc { should_skip_callback? }

... Where a model has many callbacks, this can quickly become very tedious and result in noisy code. So I have taken it upon myself to add this functionality within ActiveRecord, so you can now call:

Foo.create_without_callbacks
Foo.create_without_callbacks!
@foo.save_without_callbacks
@foo.save_without_callbacks!
@foo.update_attribute_without_callbacks(:bar, "bar")
@foo.update_attributes_without_callbacks(:bar => "bar")
@foo.update_attributes_without_callbacks!(:bar => "bar")
@foo.destroy_without_callbacks

I hope others will find this to be useful, I've seen quite a few posts on Stack Overflow where people are wanting to be able to do this:

http://stackoverflow.com/questions/4491728/rails3-disable-activerecord-callbacks
http://stackoverflow.com/questions/632742/how-can-i-avoid-running-activerecord-callbacks
http://stackoverflow.com/questions/1342761/how-to-skip-activerecord-callbacks

etc.

Thank you.