Skip to content

Commit

Permalink
Fix HasManyAssociation#create ignoring the :primary_key option [#1633
Browse files Browse the repository at this point in the history
…state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
  • Loading branch information
Roman Shterenzon authored and fcheung committed Dec 27, 2008
1 parent f9cab0e commit 21efba4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -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

Expand Down
Expand Up @@ -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

1 comment on commit 21efba4

@jwulff
Copy link

@jwulff jwulff commented on 21efba4 Mar 10, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hell yes

Please sign in to comment.