diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-04 15:32:46 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-05 09:51:12 +0900 |
commit | e117d9266e577675afe1462e37601c029e21091b (patch) | |
tree | 4fdd56909796107887a97455c9559b63af4d935e /activerecord/lib/active_record/locking | |
parent | 7e658588fa15e799614268f1f733946bf2ef26cd (diff) | |
download | rails-e117d9266e577675afe1462e37601c029e21091b.tar.gz rails-e117d9266e577675afe1462e37601c029e21091b.tar.bz2 rails-e117d9266e577675afe1462e37601c029e21091b.zip |
`id_in_database` should be respected as primary key value for persisted records
Currently primary key value can not be updated if a record has a locking
column because of `_update_record` in `Locking::Optimistic` doesn't
respect `id_in_database` as primary key value unlike in `Persistence`.
And also, if a record has dirty primary key value, it may destroy any
other record by the lock version of dirty record itself.
When updating/destroying persisted records, it should identify
themselves by `id_in_database`, not by dirty primary key value.
Diffstat (limited to 'activerecord/lib/active_record/locking')
-rw-r--r-- | activerecord/lib/active_record/locking/optimistic.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index bf17f27e68..052b5d23aa 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -94,7 +94,7 @@ module ActiveRecord relation = self.class.unscoped affected_rows = relation.where( - self.class.primary_key => id, + self.class.primary_key => id_in_database, lock_col => previous_lock_value ).update_all( attributes_for_update(attribute_names).map do |name| |