aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-11-13 17:16:24 +0100
committerTeddy Wing2017-11-13 17:16:24 +0100
commit336dab9900aee831e73113e400609ec2ebd40c20 (patch)
tree4db533e1e07d1c6f55871bef61b4adeb7945ea15 /app
parent95095886ceb51a2036eea6ffda103d3ad590322b (diff)
downloadchouette-core-336dab9900aee831e73113e400609ec2ebd40c20.tar.bz2
Import: Destroy associated `Referential` on destroy if ready:false
If the `Import`'s associated `Referential` has `ready: false`, destroy that `Referential` when the import is destroyed. Aaand looking back at the task it turns out that's not what I was supposed to do. Right, it does seem a little weird in retrospect. Instead we want to delete the `Referential`s of child imports. Refs #4962
Diffstat (limited to 'app')
-rw-r--r--app/models/import.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 20e7f2d8a..68cb62f86 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -22,6 +22,7 @@ class Import < ActiveRecord::Base
validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.import.attributes.file.wrong_file_extension')
before_create :initialize_fields
+ before_destroy :destroy_non_ready_referential
def self.model_name
ActiveModel::Name.new Import, Import, "Import"
@@ -97,6 +98,12 @@ class Import < ActiveRecord::Base
self.token_download = SecureRandom.urlsafe_base64
end
+ def destroy_non_ready_referential
+ if !referential.ready
+ referential.destroy
+ end
+ end
+
def self.symbols_with_indifferent_access(array)
array.flat_map { |symbol| [symbol, symbol.to_s] }
end