mirror of https://github.com/rails/rails
Merge pull request #41025 from uxxman/destroy_async_sti_fix
Handle STI models for has_many dependent: :destroy_async Fixes #41008.
This commit is contained in:
commit
7f0bbed4b3
|
@ -42,7 +42,7 @@ module ActiveRecord
|
|||
enqueue_destroy_association(
|
||||
owner_model_name: owner.class.to_s,
|
||||
owner_id: owner.id,
|
||||
association_class: association_class.to_s,
|
||||
association_class: reflection.klass.to_s,
|
||||
association_ids: ids,
|
||||
association_primary_key_column: primary_key_column,
|
||||
ensuring_owner_was_method: options.fetch(:ensuring_owner_was, nil)
|
||||
|
|
|
@ -134,6 +134,16 @@ class DestroyAssociationAsyncTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "has_many with sti parent class destroys all children class records" do
|
||||
book = BookDestroyAsync.create!
|
||||
LongEssayDestroyAsync.create!(book: book)
|
||||
ShortEssayDestroyAsync.create!(book: book)
|
||||
book.destroy
|
||||
|
||||
assert_difference -> { EssayDestroyAsync.count }, -2 do
|
||||
perform_enqueued_jobs only: ActiveRecord::DestroyAssociationAsyncJob
|
||||
end
|
||||
end
|
||||
|
||||
test "enqueues the has_many to be deleted with custom primary key" do
|
||||
dl_keyed_has_many = DlKeyedHasMany.new
|
||||
|
|
|
@ -4,3 +4,9 @@ class EssayDestroyAsync < ActiveRecord::Base
|
|||
self.table_name = "essays"
|
||||
belongs_to :book, dependent: :destroy_async, class_name: "BookDestroyAsync"
|
||||
end
|
||||
|
||||
class LongEssayDestroyAsync < EssayDestroyAsync
|
||||
end
|
||||
|
||||
class ShortEssayDestroyAsync < EssayDestroyAsync
|
||||
end
|
||||
|
|
|
@ -408,6 +408,7 @@ ActiveRecord::Schema.define do
|
|||
end
|
||||
|
||||
create_table :essays, force: true do |t|
|
||||
t.string :type
|
||||
t.string :name
|
||||
t.string :writer_id
|
||||
t.string :writer_type
|
||||
|
|
Loading…
Reference in New Issue