aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 50166c4385..828a8b41b6 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -102,12 +102,21 @@ module ActiveRecord
became
end
- # Updates a single attribute and saves the record without going through the normal validation procedure.
- # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
- # in Base is replaced with this when the validations module is mixed in, which it is by default.
+ # Updates a single attribute and saves the record without going through the normal validation procedure
+ # or callbacks. This is especially useful for boolean flags on existing records.
def update_attribute(name, value)
send("#{name}=", value)
- save(:validate => false)
+ hash = { name => read_attribute(name) }
+
+ if record_update_timestamps
+ timestamp_attributes_for_update_in_model.each do |column|
+ hash[column] = read_attribute(column)
+ end
+ end
+
+ @changed_attributes.delete(name.to_s)
+ primary_key = self.class.primary_key
+ self.class.update_all(hash, { primary_key => self[primary_key] }) == 1
end
# Updates all the attributes from the passed-in Hash and saves the record.
@@ -234,4 +243,4 @@ module ActiveRecord
end
end
end
-end \ No newline at end of file
+end