aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-03-04 15:32:46 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-03-05 09:51:12 +0900
commite117d9266e577675afe1462e37601c029e21091b (patch)
tree4fdd56909796107887a97455c9559b63af4d935e /activerecord/lib/active_record/persistence.rb
parent7e658588fa15e799614268f1f733946bf2ef26cd (diff)
downloadrails-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/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index c9f929680b..8f9cb85a90 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -691,7 +691,7 @@ module ActiveRecord
end
def _relation_for_itself
- self.class.unscoped.where(self.class.primary_key => id)
+ self.class.unscoped.where(self.class.primary_key => id_in_database)
end
def create_or_update(*args, &block)