How to Avoid Running Activerecord Callbacks

How can I avoid running ActiveRecord callbacks?

This solution is Rails 2 only.

I just investigated this and I think I have a solution. There are two ActiveRecord private methods that you can use:

update_without_callbacks
create_without_callbacks

You're going to have to use send to call these methods. examples:

p = Person.new(:name => 'foo')
p.send(:create_without_callbacks)

p = Person.find(1)
p.send(:update_without_callbacks)

This is definitely something that you'll only really want to use in the console or while doing some random tests. Hope this helps!

How to skip ActiveRecord callbacks?

For Rails 2, but not Rails 3 you can use these:

object.send(:create_without_callbacks)
object.send(:update_without_callbacks)

How to disable ActiveRecord callbacks in Rails 3?

  1. See the question: How can I avoid running ActiveRecord callbacks?
  2. This blog post has another explanation with example.


Related Topics



Leave a reply



Submit