Merge pull request #48400 from adrianna-chang-shopify/ac-scope-for-create-on-cpk

Fix `#scope_for_create` for belongs_to associations with CPK
This commit is contained in:
Eileen M. Uchitelle 2023-06-06 09:04:22 -04:00 committed by GitHub
commit e7be1e76bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -34,7 +34,7 @@ module ActiveRecord
private
def scope_for_create
super.except!(klass.primary_key)
super.except!(*Array(klass.primary_key))
end
def find_target

View File

@ -35,7 +35,7 @@ require "models/cpk"
class BelongsToAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :topics,
:developers_projects, :computers, :authors, :author_addresses,
:essays, :posts, :tags, :taggings, :comments, :sponsors, :members, :nodes
:essays, :posts, :tags, :taggings, :comments, :sponsors, :members, :nodes, :cpk_books
def test_belongs_to
client = Client.find(3)
@ -356,6 +356,15 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal apple.id, citibank.firm_id
end
def test_building_the_belonging_object_for_composite_primary_key
cpk_book = cpk_books(:cpk_great_author_first_book)
order = cpk_book.build_order
cpk_book.save
_shop_id, id = order.id
assert_equal id, cpk_book.order_id
end
def test_building_the_belonging_object_with_implicit_sti_base_class
account = Account.new
company = account.build_firm