diff options
| author | teddywing | 2017-11-06 12:36:17 +0100 |
|---|---|---|
| committer | GitHub | 2017-11-06 12:36:17 +0100 |
| commit | 1b70d5584f59fb3afd47030904bc16daa9f200bc (patch) | |
| tree | f90611dec75bf50a2a54e5ce37b469bac61220a2 /app | |
| parent | 94d240c3ae5511591452aa1a43c90811b0c571dd (diff) | |
| parent | ea1cbc874aa6609c6217514640eb1eca20665d41 (diff) | |
| download | chouette-core-1b70d5584f59fb3afd47030904bc16daa9f200bc.tar.bz2 | |
Merge pull request #109 from af83/4802-referential-model-normalisation
4802 referential model normalisation
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/referential.rb | 12 | ||||
| -rw-r--r-- | app/models/referential_suite.rb | 13 |
2 files changed, 23 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 diff --git a/app/models/referential_suite.rb b/app/models/referential_suite.rb index 9fd25ef3f..93c2c3f36 100644 --- a/app/models/referential_suite.rb +++ b/app/models/referential_suite.rb @@ -1,6 +1,19 @@ class ReferentialSuite < ActiveRecord::Base belongs_to :new, class_name: 'Referential' + validate def validate_consistent_new + return true if new_id.nil? + return true if new.referential_suite_id == id + errors.add(:inconsistent_new, + I18n.t('referential_suites.errors.inconsistent_new', name: new.name)) + end + belongs_to :current, class_name: 'Referential' + validate def validate_consistent_current + return true if current_id.nil? + return true if current.referential_suite_id == id + errors.add(:inconsistent_current, + I18n.t('referential_suites.errors.inconsistent_current', name: current.name)) + end has_many :referentials end |
