Class: ActiveRecord::DestroyAssociationAsyncJob

Inherits:
ActiveJob::Base show all
Defined in:
activerecord/lib/active_record/destroy_association_async_job.rb

Overview

Active Record Destroy Association Async Job

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

Constant Summary

Constants included from ActiveSupport::Callbacks

ActiveSupport::Callbacks::CALLBACK_FILTER_TYPES

Instance Attribute Summary

Attributes included from ActiveJob::Core

#arguments, #enqueue_error, #enqueued_at, #exception_executions, #executions, #job_id, #locale, #priority, #provider_job_id, #queue_name, #scheduled_at, #serialized_arguments, #successfully_enqueued, #timezone

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from ActiveJob::Logging

#perform_now

Methods included from ActiveJob::Instrumentation

#perform_now

Methods included from ActiveJob::Exceptions

#retry_job

Methods included from ActiveSupport::Callbacks

#run_callbacks

Methods included from ActiveJob::Execution

#perform_now

Methods included from ActiveSupport::Rescuable

#handler_for_rescue, #rescue_with_handler

Methods included from ActiveJob::Enqueuing

#enqueue

Methods included from ActiveJob::QueuePriority

#priority

Methods included from ActiveJob::QueueName

#queue_name

Methods included from ActiveJob::Core

#deserialize, #initialize, #serialize, #set, #successfully_enqueued?

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'activerecord/lib/active_record/destroy_association_async_job.rb', line 15

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 => [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