diff options
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/primary_key.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index cb550b0683..1c81a5b71b 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -15,9 +15,10 @@ module ActiveRecord # Returns the primary key value. def id - return unless self.class.primary_key - sync_with_transaction_state - read_attribute(self.class.primary_key) + if pk = self.class.primary_key + sync_with_transaction_state + read_attribute(pk) + end end # Sets the primary key value. diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 6d1897ab40..86b4cc90ea 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -380,7 +380,11 @@ module ActiveRecord # Delegates to id in order to allow two records of the same type and id to work with something like: # [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ] def hash - (id || object_id).hash + if id + id.hash + else + super + end end # Clone and freeze the attributes hash such that associations are still |