diff options
| author | Sean Griffin <sean@thoughtbot.com> | 2014-06-12 18:21:01 -0600 |
|---|---|---|
| committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-12 18:21:01 -0600 |
| commit | 607e335faeeab965d2ba28a7ca2cbb19e2878c62 (patch) | |
| tree | 390db816b66c18b8a67187c1bf5f7f800b39f91e | |
| parent | 1cec61fc13a9809b616f1dcc74c1a9ccea9db08c (diff) | |
| download | rails-607e335faeeab965d2ba28a7ca2cbb19e2878c62.tar.gz rails-607e335faeeab965d2ba28a7ca2cbb19e2878c62.tar.bz2 rails-607e335faeeab965d2ba28a7ca2cbb19e2878c62.zip | |
Use a conditional rather than early return in `id`
| -rw-r--r-- | activerecord/lib/active_record/attribute_methods/primary_key.rb | 7 |
1 files changed, 4 insertions, 3 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. |
