Permalink
Browse files

Redirect method missing for primary key to read_attribute

  • Loading branch information...
1 parent 9cdcfb4 commit f8d2c77c9056e16d4f98020c94f9316835c4e099 @josh josh committed Jul 30, 2009
View
4 activerecord/lib/active_record/attribute_methods.rb
@@ -148,9 +148,7 @@ def method_missing(method_id, *args, &block)
end
guard_private_attribute_method!(method_name, args)
- if self.class.primary_key.to_s == method_name
- id
- elsif md = self.class.match_attribute_method?(method_name)
+ if md = self.class.match_attribute_method?(method_name)
attribute_name, method_type = md.pre_match, md.to_s
if attribute_name == 'id' || @attributes.include?(attribute_name)
__send__("attribute#{method_type}", attribute_name, *args, &block)
View
4 activerecord/lib/active_record/attribute_methods/read.rb
@@ -62,6 +62,7 @@ def define_read_method(symbol, attr_name, column)
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
attr_name = attr_name.to_s
+ attr_name = self.class.primary_key if attr_name == 'id'
if !(value = @attributes[attr_name]).nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
@@ -84,8 +85,7 @@ def id
column = column_for_attribute(attr_name)
self.class.send(:define_read_method, :id, attr_name, column)
- # now that the method exists, call it
- self.send attr_name.to_sym
+ id
end
# Returns true if the attribute is of a text column and marked for serialization.

0 comments on commit f8d2c77

Please sign in to comment.