提交 7276128f 编写于 作者: R Roman Shterenzon 提交者: Yehuda Katz

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

Signed-off-by: NFrederick Cheung <frederick.cheung@gmail.com>
上级 27cfeb7c
......@@ -180,7 +180,10 @@ def set_belongs_to_association_for(record)
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
......
......@@ -1115,5 +1115,11 @@ def test_respond_to_private_class_methods
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册