diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 20:55:05 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 20:55:05 +0000 |
commit | def61a200e6021a532cd1bcc28541397fdc984b4 (patch) | |
tree | 28ebf5c9c72ad3cd47fa66e325b0e985b077b343 | |
parent | cb7a17a9d083082709f62ccbca3a2c1ef8e0c87b (diff) | |
download | rails-def61a200e6021a532cd1bcc28541397fdc984b4.tar.gz rails-def61a200e6021a532cd1bcc28541397fdc984b4.tar.bz2 rails-def61a200e6021a532cd1bcc28541397fdc984b4.zip |
Call the newly generated read method after generating it. Closes #8470.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6837 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index bf5ee1854d..608651cd0a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1621,8 +1621,14 @@ module ActiveRecord #:nodoc: def id attr_name = self.class.primary_key column = column_for_attribute(attr_name) - define_read_method(:id, attr_name, column) if self.class.generate_read_methods - read_attribute(attr_name) + + if self.class.generate_read_methods + define_read_method(:id, attr_name, column) + # now that the method exists, call it + self.send attr_name.to_sym + else + read_attribute(attr_name) + end end # Enables Active Record objects to be used as URL parameters in Action Pack automatically. @@ -1976,8 +1982,13 @@ module ActiveRecord #:nodoc: (md = /\?$/.match(method_name) and @attributes.include?(query_method_name = md.pre_match) and method_name = query_method_name) - define_read_methods if self.class.read_methods.empty? && self.class.generate_read_methods - md ? query_attribute(method_name) : read_attribute(method_name) + if self.class.read_methods.empty? && self.class.generate_read_methods + define_read_methods + # now that the method exists, call it + self.send method_id.to_sym + else + md ? query_attribute(method_name) : read_attribute(method_name) + end elsif self.class.primary_key.to_s == method_name id elsif md = self.class.match_attribute_method?(method_name) |