diff options
| author | Zog | 2018-01-08 16:13:22 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-11 11:17:10 +0100 | 
| commit | dad755a814b087af1ba30b27cf966b9c914dfa51 (patch) | |
| tree | 5c50ea0da7cf85ab39958a66805cc1bd773ede6b /app/models/chouette | |
| parent | f7ed3ca6615bb4950b644d56136016c4482395a8 (diff) | |
| download | chouette-core-dad755a814b087af1ba30b27cf966b9c914dfa51.tar.bz2 | |
Refs #5500 @3h; Add filters on ReferentialVJ#index
To enable users to filter on stop areas
Diffstat (limited to 'app/models/chouette')
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 13 | 
1 files changed, 13 insertions, 0 deletions
| diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 11da77948..a8c9c1824 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -22,6 +22,7 @@ module Chouette      belongs_to :company      belongs_to :route      belongs_to :journey_pattern +    has_many :stop_areas, through: :journey_pattern      has_and_belongs_to_many :footnotes, :class_name => 'Chouette::Footnote'      has_and_belongs_to_many :purchase_windows, :class_name => 'Chouette::PurchaseWindow' @@ -42,6 +43,18 @@ module Chouette      before_validation :set_default_values,        :calculate_vehicle_journey_at_stop_day_offset +    scope :with_stop_area_ids, ->(ids){ +      _ids = ids.select(&:present?).map(&:to_i) +      if _ids.present? +        where("array(SELECT stop_points.stop_area_id::integer FROM stop_points INNER JOIN journey_patterns_stop_points ON journey_patterns_stop_points.stop_point_id = stop_points.id WHERE journey_patterns_stop_points.journey_pattern_id = vehicle_journeys.journey_pattern_id) @> array[?]", _ids) +      else +        all +      end +    } + +    # We need this for the ransack object in the filters +    ransacker :stop_area_ids +      # TODO: Remove this validator      # We've eliminated this validation because it prevented vehicle journeys      # from being saved with at-stops having a day offset greater than 0, | 
