1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Handle STI models for has_many dependent: :destroy_async

Update activerecord/test/activejob/destroy_association_async_test.rb

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
This commit is contained in:
Muhammad Usman 2021-01-06 00:24:28 +01:00
parent 8a91423b92
commit 095878c6e4
4 changed files with 18 additions and 1 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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