aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-07-30 13:33:12 -0500
committerJoshua Peek <josh@joshpeek.com>2009-07-30 17:54:01 -0500
commitf8d2c77c9056e16d4f98020c94f9316835c4e099 (patch)
treef13f7da8cab3d6664ef35f095cabde16fae1fcb6 /activerecord/lib
parent9cdcfb4fc5992d51d0773d88bfc1d97c089d536b (diff)
downloadrails-f8d2c77c9056e16d4f98020c94f9316835c4e099.tar.gz
rails-f8d2c77c9056e16d4f98020c94f9316835c4e099.tar.bz2
rails-f8d2c77c9056e16d4f98020c94f9316835c4e099.zip
Redirect method missing for primary key to read_attribute
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb4
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb4
2 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 04a9932a4c..3eeb7fb4e9 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -148,9 +148,7 @@ module ActiveRecord
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)
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 7e92e0bd68..a3327dc083 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -62,6 +62,7 @@ module ActiveRecord
# "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 @@ module ActiveRecord
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.