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

Leave a comment