diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-06-30 07:14:09 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-08 22:43:18 +0200 |
commit | 01629d180468049d17a8be6900e27a4f0d2b18c4 (patch) | |
tree | d3292821180ce99b8d9f53c35ab7b32b67364c95 /activerecord/lib/active_record/persistence.rb | |
parent | 690352dce492938ab54a4b7e2befbd0a6931de3c (diff) | |
download | rails-01629d180468049d17a8be6900e27a4f0d2b18c4.tar.gz rails-01629d180468049d17a8be6900e27a4f0d2b18c4.tar.bz2 rails-01629d180468049d17a8be6900e27a4f0d2b18c4.zip |
This patch changes update_attribute implementatino so:
- it will only save the attribute it has been asked to save and not all dirty attributes
- it does not invoke callbacks
- it does change updated_at/on
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 17 |
1 files changed, 12 insertions, 5 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 |