Delegate access to a customized primary key to the conventional id method. Closes #2444.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2569 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
f0448f5631
commit
ebf618b7fc
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Delegate access to a customized primary key to the conventional id method. #2444. [Blair Zajac <blair@orcaware.com>]
|
||||
|
||||
* Fix errors caused by assigning a has-one or belongs-to property to itself
|
||||
|
||||
* Add ActiveRecord::Base.schema_format setting which specifies how databases should be dumped [Sam Stephenson]
|
||||
|
@ -1331,6 +1331,8 @@ def method_missing(method_id, *args, &block)
|
||||
if @attributes.include?(method_name)
|
||||
define_read_methods if self.class.read_methods.empty? && self.class.generate_read_methods
|
||||
read_attribute(method_name)
|
||||
elsif self.class.primary_key.to_s == method_name
|
||||
id
|
||||
elsif md = /(=|\?|_before_type_cast)$/.match(method_name)
|
||||
attribute_name, method_type = md.pre_match, md.to_s
|
||||
if @attributes.include?(attribute_name)
|
||||
|
@ -30,10 +30,10 @@ def test_customized_primary_key_auto_assigns_on_save
|
||||
assert_equal keyboard.id, Keyboard.find_by_name('HHKB').id
|
||||
end
|
||||
|
||||
def test_customized_primary_key_can_be_set_before_saving
|
||||
def test_customized_primary_key_can_be_get_before_saving
|
||||
keyboard = Keyboard.new
|
||||
assert_respond_to(keyboard, :key_number)
|
||||
assert_nothing_raised { keyboard.key_number = 1 }
|
||||
assert_nothing_raised { keyboard.key_number }
|
||||
end
|
||||
|
||||
def test_customized_string_primary_key_settable_before_save
|
||||
|
Loading…
Reference in New Issue
Block a user