diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-26 13:59:14 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-26 13:59:14 -0400 |
commit | 6be22632b12a0700630fda9d154afa2386a97f10 (patch) | |
tree | c9b7215bbc1881902e2bbe5b285bf5404217a846 /activerecord/lib/active_record | |
parent | 6f9b01c056cd2f3a4761baf78df207e1154f1b06 (diff) | |
download | rails-6be22632b12a0700630fda9d154afa2386a97f10.tar.gz rails-6be22632b12a0700630fda9d154afa2386a97f10.tar.bz2 rails-6be22632b12a0700630fda9d154afa2386a97f10.zip |
Use `_relation_for_itself` wherever possible
Anywhere that we're doing `self.class.unscoped.where(primary_key => id)`
is somewhere that someone may want to extend. Even if this method isn't
public API yet, this will make it easier for us to eventually expose an
API around this. Plus, duplicated code makes me sad.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 4bd14ccf29..1297e0cde7 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -332,7 +332,7 @@ module ActiveRecord verify_readonly_attribute(key.to_s) end - updated_count = self.class.unscoped.where(self.class.primary_key => id).update_all(attributes) + updated_count = _relation_for_itself.update_all(attributes) attributes.each do |k, v| write_attribute_without_type_cast(k, v) @@ -523,8 +523,7 @@ module ActiveRecord changes[column] = write_attribute(column, time) end - primary_key = self.class.primary_key - scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key)) + scope = _relation_for_itself if locking_enabled? locking_column = self.class.locking_column |