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.rb23
1 files changed, 14 insertions, 9 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb
index afadf5edd..8b8df3294 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -30,7 +30,7 @@ class Referential < ActiveRecord::Base
validates_presence_of :line_referential
belongs_to :created_from, class_name: 'Referential'
- has_many :lines, through: :line_referential
+ has_many :associated_lines, through: :line_referential, source: :lines
has_many :companies, through: :line_referential
has_many :group_of_lines, through: :line_referential
has_many :networks, through: :line_referential
@@ -43,6 +43,10 @@ class Referential < ActiveRecord::Base
has_many :stop_areas, through: :stop_area_referential
belongs_to :workbench
+ def lines
+ workbench ? workbench.lines : associated_lines
+ end
+
def slug_excluded_values
if ! slug.nil?
if slug.start_with? "pg_"
@@ -128,13 +132,6 @@ class Referential < ActiveRecord::Base
})
end
- def clone_association from
- self.organisation = from.organisation
- self.line_referential = from.line_referential
- self.stop_area_referential = from.stop_area_referential
- self.workbench = from.workbench
- end
-
def self.available_srids
[
[ "RGF 93 Lambert 93 (2154)", 2154 ],
@@ -171,7 +168,8 @@ class Referential < ActiveRecord::Base
projection_type || ""
end
- before_validation :assign_line_and_stop_area_referential, :on => :create, if: :workbench
+ before_validation :assign_line_and_stop_area_referential, :on => :create, if: :workbench, unless: :created_from
+ before_validation :clone_associations, :on => :create, if: :created_from
before_create :create_schema
after_create :create_referential_metadata, if: :workbench, unless: :created_from
@@ -185,6 +183,13 @@ class Referential < ActiveRecord::Base
self.referential_metadatas.create
end
+ def clone_associations
+ self.organisation = created_from.organisation
+ self.line_referential = created_from.line_referential
+ self.stop_area_referential = created_from.stop_area_referential
+ self.workbench = created_from.workbench
+ end
+
def clone_referential_metadatas
self.created_from.referential_metadatas.each do |meta|
self.referential_metadatas << ReferentialMetadata.new_from(meta)