aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/persistence.rb17
-rw-r--r--activerecord/lib/active_record/timestamp.rb12
2 files changed, 22 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 50166c4385..8d093c81de 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -102,12 +102,19 @@ 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)
+ primary_key = self.class.primary_key
+ h = {name => value}
+ if should_record_update_timestamps
+ self.send(:record_update_timestamps)
+ current_time = current_time_from_proper_timezone
+ timestamp_attributes_for_update_in_model.each { |column| h.merge!(column => current_time) }
+ end
+ self.class.update_all(h, {primary_key => self[primary_key]}) == 1
+ @changed_attributes.delete(name.to_s)
end
# Updates all the attributes from the passed-in Hash and saves the record.
@@ -234,4 +241,4 @@ module ActiveRecord
end
end
end
-end \ No newline at end of file
+end
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb
index da8324ddcc..e6d52744df 100644
--- a/activerecord/lib/active_record/timestamp.rb
+++ b/activerecord/lib/active_record/timestamp.rb
@@ -58,14 +58,22 @@ module ActiveRecord
end
def update(*args) #:nodoc:
- if record_timestamps && (!partial_updates? || changed?)
+ record_update_timestamps
+ super
+ end
+
+ def record_update_timestamps
+ if should_record_update_timestamps
current_time = current_time_from_proper_timezone
timestamp_attributes_for_update_in_model.each { |column| write_attribute(column.to_s, current_time) }
end
+ end
- super
+ def should_record_update_timestamps
+ record_timestamps && (!partial_updates? || changed?)
end
+
def timestamp_attributes_for_update #:nodoc:
[:updated_at, :updated_on]
end