Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix HasManyAssociation#create ignoring the :primary_key option [#1633

…state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
  • Loading branch information...
commit 7276128fb47d5997437eb5452b4e9a82ee54f4a8 1 parent 27cfeb7
@romanbsd romanbsd authored wycats committed
View
5 activerecord/lib/active_record/associations/association_proxy.rb
@@ -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
View
6 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.