diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-06 23:09:11 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-06 23:17:56 -0200 |
commit | 0e67f793cd67ad96abbe7e9b3ba1363fdedb8e71 (patch) | |
tree | b762980bebad7c1916df6ac806daec5ecafe3f05 /activerecord/CHANGELOG.md | |
parent | 1eaf3db80415798bfd1395e104bc12985109a4f6 (diff) | |
download | rails-0e67f793cd67ad96abbe7e9b3ba1363fdedb8e71.tar.gz rails-0e67f793cd67ad96abbe7e9b3ba1363fdedb8e71.tar.bz2 rails-0e67f793cd67ad96abbe7e9b3ba1363fdedb8e71.zip |
Unscope update_column(s) query to ignore default scope
When applying default_scope to a class with a where clause, using
update_column(s) could generate a query that would not properly update
the record due to the where clause from the default_scope being applied
to the update query.
class User < ActiveRecord::Base
default_scope where(active: true)
end
user = User.first
user.active = false
user.save!
user.update_column(:active, true) # => false
In this situation we want to skip the default_scope clause and just
update the record based on the primary key. With this change:
user.update_column(:active, true) # => true
Fixes #8436.
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 4e48c386bd..e79c7cb64f 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,31 @@ ## Rails 4.0.0 (unreleased) ## +* Unscope `update_column(s)` query to ignore default scope. + + When applying `default_scope` to a class with a where clause, using + `update_column(s)` could generate a query that would not properly update + the record due to the where clause from the `default_scope` being applied + to the update query. + + class User < ActiveRecord::Base + default_scope where(active: true) + end + + user = User.first + user.active = false + user.save! + + user.update_column(:active, true) # => false + + In this situation we want to skip the default_scope clause and just + update the record based on the primary key. With this change: + + user.update_column(:active, true) # => true + + Fixes #8436. + + *Carlos Antonio da Silva* + * SQLite adapter no longer corrupts binary data if the data contains `%00`. *Chris Feist* |