Permalink
Browse files

Merge pull request #15677 from sgrif/sg-less-imperative-pk

Use a conditional rather than early return in `id`
  • Loading branch information...
2 parents 86bbfbc + 607e335 commit 7eb110f104209208e4c76306775cc3bc6e9f129f @matthewd matthewd committed Jun 13, 2014
Showing with 4 additions and 3 deletions.
  1. +4 −3 activerecord/lib/active_record/attribute_methods/primary_key.rb
View
7 activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -15,9 +15,10 @@ def to_key
# 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.

0 comments on commit 7eb110f

Please sign in to comment.