diff options
author | Henrik N <henrik@nyh.se> | 2012-10-28 17:48:04 +0100 |
---|---|---|
committer | Henrik N <henrik@nyh.se> | 2012-10-28 21:28:54 +0100 |
commit | 1849665f738cf7b3650e508b05380ebb36748f9e (patch) | |
tree | 6e741da75ee9246fc85ca6bc1c222c7169681690 /activerecord/lib/active_record | |
parent | 5bbe245a51cec029101c844e159ba7f7a7afedab (diff) | |
download | rails-1849665f738cf7b3650e508b05380ebb36748f9e.tar.gz rails-1849665f738cf7b3650e508b05380ebb36748f9e.tar.bz2 rails-1849665f738cf7b3650e508b05380ebb36748f9e.zip |
Enable update_column(s) for the primary key attribute.
Didn't work before because it updated the model-in-memory first, so the DB query couldn't find the record.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 611d3d97c3..c336e1f5bb 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -224,11 +224,13 @@ module ActiveRecord verify_readonly_attribute(key.to_s) end + updated_count = self.class.where(self.class.primary_key => id).update_all(attributes) + attributes.each do |k,v| raw_write_attribute(k,v) end - self.class.where(self.class.primary_key => id).update_all(attributes) == 1 + updated_count == 1 end # Initializes +attribute+ to zero if +nil+ and adds the value passed as +by+ (default is 1). |