diff options
author | Marcel Molina <marcel@vernix.org> | 2005-10-13 20:44:39 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2005-10-13 20:44:39 +0000 |
commit | ebf618b7fc39d66852f666c12b79fd6e71da0e3a (patch) | |
tree | 6b61e6e86ee913a3d2b5f4fe7a866bde2d0e071b | |
parent | f0448f5631288e3b73f9c95ebc1870dd54967a87 (diff) | |
download | rails-ebf618b7fc39d66852f666c12b79fd6e71da0e3a.tar.gz rails-ebf618b7fc39d66852f666c12b79fd6e71da0e3a.tar.bz2 rails-ebf618b7fc39d66852f666c12b79fd6e71da0e3a.zip |
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
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rw-r--r-- | activerecord/test/pk_test.rb | 4 |
3 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 5024362bf5..dc9bb28862 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3f0201a202..8af2c33ce5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1331,6 +1331,8 @@ module ActiveRecord #:nodoc: 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) diff --git a/activerecord/test/pk_test.rb b/activerecord/test/pk_test.rb index 24f9bc4097..d77982df1b 100644 --- a/activerecord/test/pk_test.rb +++ b/activerecord/test/pk_test.rb @@ -30,10 +30,10 @@ class PrimaryKeysTest < Test::Unit::TestCase 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 |