Skip to content

Instantly share code, notes, and snippets.

@mikezter
Created February 22, 2010 17:40
Show Gist options
  • Save mikezter/311287 to your computer and use it in GitHub Desktop.
Save mikezter/311287 to your computer and use it in GitHub Desktop.
update a single attribute on dirty ActiveRecords
module ActiveRecord
class Base
# updates a single attribute on the record directly to the database using
# ActiveRecord::Base.update_all
def update_single_attribute(name, value)
write_attribute(name, value)
self.class.update_all({name => value}, {self.class.primary_key => read_attribute(self.class.primary_key)}, {:limit => 1})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment