Purge all dossier with state draft
This commit is contained in:
parent
71de64e3ec
commit
fd6b1f15a0
3 changed files with 32 additions and 2 deletions
25
db/migrate/20161005144657_purge_draft_dossier.rb
Normal file
25
db/migrate/20161005144657_purge_draft_dossier.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class PurgeDraftDossier < ActiveRecord::Migration
|
||||
class Dossier < ActiveRecord::Base
|
||||
BROUILLON = %w(draft)
|
||||
|
||||
def brouillon?
|
||||
BROUILLON.include?(state)
|
||||
end
|
||||
end
|
||||
|
||||
class Commentaire < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
end
|
||||
|
||||
class Cerfa < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
def change
|
||||
Cerfa.all.each { |cerfa| cerfa.delete if cerfa.dossier.brouillon? }
|
||||
Commentaire.all.each { |com| com.delete if com.dossier.brouillon? }
|
||||
|
||||
Dossier.where(state: :draft).destroy_all
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue