update_attribute_without_callbacks and update_attributes_without_callbacks

When you got slow callbacks or just want to set something without callbacks interfering.
Executes raw sql and sets the new values, no validations, no callbacks.

class ActiveRecord::Base
  def update_attribute_without_callbacks(attribute, value)
    update_attributes_without_callbacks(attribute=>value)
  end

  def update_attributes_without_callbacks(attributes)
    self.class.update_all(attributes,{:id=>id})
    attributes.each{|k,v| send("#{k}=",v)}
  end
end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s