Permalink
Browse files

recurse in read_attribute we get caching / don't duplicate code

  • Loading branch information...
1 parent 130064d commit 7dd7d76b86b2168b39fb7f0c359d84ea6df0ce41 @jonleighton jonleighton committed Mar 30, 2012
Showing with 2 additions and 3 deletions.
  1. +2 −3 activerecord/lib/active_record/attribute_methods/read.rb
@@ -67,9 +67,8 @@ def read_attribute(attr_name)
@attributes_cache.fetch(attr_name.to_s) { |name|
column = @columns_hash.fetch(name) {
return @attributes.fetch(name) {
- if name == 'id'
- primary_key = self.class.primary_key
- @columns_hash[primary_key].type_cast(@attributes[primary_key])
+ if name == 'id' && self.class.primary_key != name
+ read_attribute(self.class.primary_key)
end
}
}

0 comments on commit 7dd7d76

Please sign in to comment.