aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/chouette/vehicle_journey.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 852139625..514e89fb1 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -252,5 +252,26 @@ module Chouette
)
end
+ def self.exclude_journeys_without_time_tables
+ # Joins the VehicleJourney–TimeTable through table to remove
+ # VehicleJourneys that don't have an associated TimeTable. The subquery
+ # allows us to select unique VehicleJourney IDs from the through table,
+ # which prevents VehicleJourneys from appearing multiple times in the
+ # result set due to the join. Using a DISTINCT in a subquery avoids messy
+ # DISTINCT and GROUP BY clauses in the main query.
+ self
+ .joins('
+ LEFT JOIN (
+ SELECT DISTINCT
+ "time_tables_vehicle_journeys"."vehicle_journey_id"
+ FROM "time_tables_vehicle_journeys"
+ ) AS "distinct_time_tables_vehicle_journeys"
+ ON "distinct_time_tables_vehicle_journeys"."vehicle_journey_id" =
+ "vehicle_journeys"."id"
+ ')
+ .where('"distinct_time_tables_vehicle_journeys"."vehicle_journey_id"
+ IS NOT NULL')
+ end
+
end
end