aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorVlatka Pavisic2017-04-11 15:35:01 +0200
committerVlatka Pavisic2017-04-11 15:35:01 +0200
commitaa481c087b162bc775b4418e205f91c5b6bead19 (patch)
tree914ba9b39e0338317bcc2bfd839f745647beda1a /app/models
parent8adf909694b52959483818bf839d6e180015eb99 (diff)
downloadchouette-core-aa481c087b162bc775b4418e205f91c5b6bead19.tar.bz2
Refs #3047: Associate RoutingConstraintZone with StopPoints
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/routing_constraint_zone.rb11
-rw-r--r--app/models/chouette/stop_point.rb6
2 files changed, 11 insertions, 6 deletions
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
index 2c8583ec1..d548ce048 100644
--- a/app/models/chouette/routing_constraint_zone.rb
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -1,9 +1,12 @@
class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord
belongs_to :route
- has_array_of :stop_areas, class_name: 'Chouette::StopArea'
+ has_array_of :stop_points, class_name: 'Chouette::StopPoint'
- validates_presence_of :name, :stop_area_ids, :route_id
- validates :stop_areas, length: { minimum: 2 }
+ validates_presence_of :name, :stop_point_ids, :route_id
+ validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }
+ validate :stop_points_belong_to_route
- self.primary_key = 'id'
+ def stop_points_belong_to_route
+ errors.add(:stop_points, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp }
+ end
end
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index b77189fc1..96b79c9e7 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -2,7 +2,7 @@ module Chouette
class StopPoint < TridentActiveRecord
include ForBoardingEnumerations
include ForAlightingEnumerations
-
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -18,6 +18,8 @@ module Chouette
scope :default_order, order("position")
+ delegate :name, to: :stop_area
+
before_destroy :remove_dependent_journey_pattern_stop_points
def remove_dependent_journey_pattern_stop_points
route.journey_patterns.each do |jp|
@@ -25,7 +27,7 @@ module Chouette
jp.stop_point_ids = jp.stop_point_ids - [id]
end
end
- end
+ end
def stop_area_id_validation
if stop_area_id.nil?