Class: ActiveRecord::DestroyAssociationAsyncJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/destroy_association_async_job.rb

Overview

Job to destroy the records associated with a destroyed record in background.

Instance Method Summary collapse

Instance Method Details

#perform(owner_model_name: nil, owner_id: nil, association_class: nil, association_ids: nil, association_primary_key_column: nil, ensuring_owner_was_method: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/destroy_association_async_job.rb', line 13

def perform(
  owner_model_name: nil, owner_id: nil,
  association_class: nil, association_ids: nil, association_primary_key_column: nil,
  ensuring_owner_was_method: nil
)
  association_model = association_class.constantize
  owner_class = owner_model_name.constantize
  owner = owner_class.find_by(owner_class.primary_key.to_sym => owner_id)

  if !owner_destroyed?(owner, ensuring_owner_was_method)
    raise DestroyAssociationAsyncError, "owner record not destroyed"
  end

  association_model.where(association_primary_key_column => association_ids).find_each do |r|
    r.destroy
  end
end