aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/referential.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/referential.rb')
-rw-r--r--app/models/referential.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb
index c7b52ddf8..ed13cd077 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
class Referential < ActiveRecord::Base
include DataFormatEnumerations
@@ -28,6 +27,15 @@ class Referential < ActiveRecord::Base
belongs_to :organisation
validates_presence_of :organisation
+ validate def validate_consistent_organisation
+ return true if workbench_id.nil?
+ ids = [workbench.organisation_id, organisation_id]
+ return true if ids.first == ids.last
+ errors.add(:inconsistent_organisation,
+ I18n.t('referentials.errors.inconsistent_organisation',
+ indirect_name: workbench.organisation.name,
+ direct_name: organisation.name))
+ end
belongs_to :line_referential
validates_presence_of :line_referential
@@ -290,7 +298,7 @@ class Referential < ActiveRecord::Base
end
def assign_prefix
- self.prefix = self.organisation.name.parameterize.gsub('-', '_')
+ self.prefix = organisation.name.parameterize.gsub('-', '_')
end
def assign_line_and_stop_area_referential