Merge pull request #3084 from tchak/destroy_dossier_operation_logs
Destroy dossier_operation_logs when dossier is destroyed
This commit is contained in:
commit
4befb57971
2 changed files with 18 additions and 1 deletions
|
@ -26,7 +26,7 @@ class Dossier < ApplicationRecord
|
|||
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
|
||||
has_many :avis, dependent: :destroy
|
||||
|
||||
has_many :dossier_operation_logs
|
||||
has_many :dossier_operation_logs, dependent: :destroy
|
||||
|
||||
belongs_to :procedure
|
||||
belongs_to :user
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: destroy_orphaned_dossier_operation_logs'
|
||||
task destroy_orphaned_dossier_operation_logs: :environment do
|
||||
bar = RakeProgressbar.new(DossierOperationLog.count)
|
||||
|
||||
DossierOperationLog.find_each do |log|
|
||||
if log.dossier.blank?
|
||||
log.destroy
|
||||
end
|
||||
bar.inc
|
||||
end
|
||||
|
||||
bar.finished
|
||||
|
||||
AfterParty::TaskRecord.create version: '20181128155650'
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue