aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-10-28 13:31:34 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-29 01:59:04 -0200
commitcdfa4a5f869b42fc3894e777d94b976ece28f716 (patch)
treeb01de638cc45e782f0a807acf3d9c829c5711fe3 /activerecord/lib/active_record/persistence.rb
parent5d82c1fc56bedb3e0b736ec06b106b2989918978 (diff)
downloadrails-cdfa4a5f869b42fc3894e777d94b976ece28f716.tar.gz
rails-cdfa4a5f869b42fc3894e777d94b976ece28f716.tar.bz2
rails-cdfa4a5f869b42fc3894e777d94b976ece28f716.zip
Merge pull request #8053 from henrik/update_columns_with_primary_key
Unbreak update_column/update_columns for the primary key attribute. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/persistence.rb activerecord/test/cases/persistence_test.rb
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 8a3c3fed7d..d492ac7f16 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -193,8 +193,12 @@ module ActiveRecord
name = name.to_s
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
raise ActiveRecordError, "can not update on a new record object" unless persisted?
+
+ updated_count = self.class.update_all({ name => value }, self.class.primary_key => id) == 1
+
raw_write_attribute(name, value)
- self.class.update_all({ name => value }, self.class.primary_key => id) == 1
+
+ updated_count == 1
end
# Updates the attributes of the model from the passed-in hash and saves the