Skip to content

Commit e7be1e7

Browse files
authored
Merge pull request rails#48400 from adrianna-chang-shopify/ac-scope-for-create-on-cpk
Fix `#scope_for_create` for belongs_to associations with CPK
2 parents f6f2b2d + e684588 commit e7be1e7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

activerecord/lib/active_record/associations/singular_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def force_reload_reader
3434

3535
private
3636
def scope_for_create
37-
super.except!(klass.primary_key)
37+
super.except!(*Array(klass.primary_key))
3838
end
3939

4040
def find_target

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
class BelongsToAssociationsTest < ActiveRecord::TestCase
3636
fixtures :accounts, :companies, :developers, :projects, :topics,
3737
:developers_projects, :computers, :authors, :author_addresses,
38-
:essays, :posts, :tags, :taggings, :comments, :sponsors, :members, :nodes
38+
:essays, :posts, :tags, :taggings, :comments, :sponsors, :members, :nodes, :cpk_books
3939

4040
def test_belongs_to
4141
client = Client.find(3)
@@ -356,6 +356,15 @@ def test_building_the_belonging_object
356356
assert_equal apple.id, citibank.firm_id
357357
end
358358

359+
def test_building_the_belonging_object_for_composite_primary_key
360+
cpk_book = cpk_books(:cpk_great_author_first_book)
361+
order = cpk_book.build_order
362+
cpk_book.save
363+
364+
_shop_id, id = order.id
365+
assert_equal id, cpk_book.order_id
366+
end
367+
359368
def test_building_the_belonging_object_with_implicit_sti_base_class
360369
account = Account.new
361370
company = account.build_firm

0 commit comments

Comments
 (0)