aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-02 18:17:54 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-02 18:17:54 -0300
commitf625b6879df4d8710c0226007dc0929ed98355d2 (patch)
tree1a58598f6f6333852509247032cc37ca7a5c2719 /activerecord
parentc8f017682e507ba6cb4183c29cf9398a20211d15 (diff)
parentb79593f84d0bc601a49e9f7470e862251b7bc145 (diff)
downloadrails-f625b6879df4d8710c0226007dc0929ed98355d2.tar.gz
rails-f625b6879df4d8710c0226007dc0929ed98355d2.tar.bz2
rails-f625b6879df4d8710c0226007dc0929ed98355d2.zip
Merge pull request #16015 from sgrif/sg-ensure-initialized
Move pk initialization logic onto `AttributeSet` Conflicts: activerecord/lib/active_record/attribute_set.rb
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_set.rb6
-rw-r--r--activerecord/lib/active_record/core.rb5
2 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb
index df4fd31e08..64df6f6358 100644
--- a/activerecord/lib/active_record/attribute_set.rb
+++ b/activerecord/lib/active_record/attribute_set.rb
@@ -58,6 +58,12 @@ module ActiveRecord
end
end
+ def ensure_initialized(key)
+ unless self[key].initialized?
+ write_from_database(key, nil)
+ end
+ end
+
protected
attr_reader :attributes
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 30b8485c8b..b11c4f804f 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -514,10 +514,7 @@ module ActiveRecord
end
def init_internals
- pk = self.class.primary_key
- if pk && !@attributes.include?(pk)
- @attributes.write_from_database(pk, nil)
- end
+ @attributes.ensure_initialized(self.class.primary_key)
@aggregation_cache = {}
@association_cache = {}