1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix HasManyAssociation#create ignoring the :primary_key option [#1633 state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
This commit is contained in:
Roman Shterenzon 2008-12-27 01:10:29 +00:00 committed by Frederick Cheung
parent f9cab0e503
commit 21efba464a
2 changed files with 10 additions and 1 deletions

View file

@ -180,7 +180,10 @@ module ActiveRecord
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s
else
record[@reflection.primary_key_name] = @owner.id unless @owner.new_record?
unless @owner.new_record?
primary_key = @reflection.options[:primary_key] || :id
record[@reflection.primary_key_name] = @owner.send(primary_key)
end
end
end

View file

@ -1115,5 +1115,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert !client_association.respond_to?(:private_method)
assert client_association.respond_to?(:private_method, true)
end
def test_creating_using_primary_key
firm = Firm.find(:first)
client = firm.clients_using_primary_key.create!(:name => 'test')
assert_equal firm.name, client.firm_name
end
end