Created
February 22, 2010 17:40
-
-
Save mikezter/311287 to your computer and use it in GitHub Desktop.
update a single attribute on dirty ActiveRecords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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