Skip to content
This repository
Browse code

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
  • Loading branch information...
commit def61a200e6021a532cd1bcc28541397fdc984b4 1 parent cb7a17a
Jeremy Kemper jeremy authored

Showing 1 changed file with 15 additions and 4 deletions. Show diff stats Hide diff stats

  1. +15 4 activerecord/lib/active_record/base.rb
19 activerecord/lib/active_record/base.rb
@@ -1621,8 +1621,14 @@ def initialize(attributes = nil)
1621 1621 def id
1622 1622 attr_name = self.class.primary_key
1623 1623 column = column_for_attribute(attr_name)
1624   - define_read_method(:id, attr_name, column) if self.class.generate_read_methods
1625   - read_attribute(attr_name)
  1624 +
  1625 + if self.class.generate_read_methods
  1626 + define_read_method(:id, attr_name, column)
  1627 + # now that the method exists, call it
  1628 + self.send attr_name.to_sym
  1629 + else
  1630 + read_attribute(attr_name)
  1631 + end
1626 1632 end
1627 1633
1628 1634 # Enables Active Record objects to be used as URL parameters in Action Pack automatically.
@@ -1976,8 +1982,13 @@ def method_missing(method_id, *args, &block)
1976 1982 (md = /\?$/.match(method_name) and
1977 1983 @attributes.include?(query_method_name = md.pre_match) and
1978 1984 method_name = query_method_name)
1979   - define_read_methods if self.class.read_methods.empty? && self.class.generate_read_methods
1980   - md ? query_attribute(method_name) : read_attribute(method_name)
  1985 + if self.class.read_methods.empty? && self.class.generate_read_methods
  1986 + define_read_methods
  1987 + # now that the method exists, call it
  1988 + self.send method_id.to_sym
  1989 + else
  1990 + md ? query_attribute(method_name) : read_attribute(method_name)
  1991 + end
1981 1992 elsif self.class.primary_key.to_s == method_name
1982 1993 id
1983 1994 elsif md = self.class.match_attribute_method?(method_name)

0 comments on commit def61a2

Please sign in to comment.
Something went wrong with that request. Please try again.