aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-09-23 15:20:39 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-09-23 15:24:55 +0530
commit730e99affb5824363599ec25445b9450b6247fde (patch)
treeae41870fcded312730774398007678a84c94b4f4 /activerecord/lib/active_record/persistence.rb
parent19966242163611e61d45ee4033f28aa6f967906a (diff)
downloadrails-730e99affb5824363599ec25445b9450b6247fde.tar.gz
rails-730e99affb5824363599ec25445b9450b6247fde.tar.bz2
rails-730e99affb5824363599ec25445b9450b6247fde.zip
Return true if attribute is not changed for update_attribute
- If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in https://github.com/rails/rails/commit/0fcd4cf5 to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes #26593.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 978fb27cab..65248f3a32 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -252,7 +252,8 @@ module ActiveRecord
name = name.to_s
verify_readonly_attribute(name)
public_send("#{name}=", value)
- save(validate: false) if changed?
+
+ changed? ? save(validate: false) : true
end
# Updates the attributes of the model from the passed-in hash and saves the