lib/gtfs/realtime/stop.rb in gtfs-realtime-0.3.0 vs lib/gtfs/realtime/stop.rb in gtfs-realtime-0.4.0

- old
+ new

@@ -3,27 +3,19 @@ module GTFS class Realtime class Stop < GTFS::Realtime::Model include GTFS::Realtime::Nearby - one_to_many :service_alerts - one_to_many :stop_times - one_to_many :stop_time_updates - many_to_many :trip_updates, join_table: :gtfs_realtime_stop_time_updates - many_to_many :trips, join_table: :gtfs_realtime_stop_times - many_through_many :routes, through: [ - [:stop_times, :stop_id, :trip_id], - [:trips, :id, :route_id] - ] - many_through_many :active_routes, class: GTFS::Realtime::Route, through: [ - [:stop_time_updates, :stop_id, :trip_update_id], - [:trip_updates, :id, :route_id] - ] + has_many :service_alerts + has_many :stop_times + has_many :stop_time_updates + has_many :trips, through: :stop_times + has_many :trip_updates, through: :stop_times + has_many :routes, through: :trips + has_many :active_routes, through: :trip_updates, source: :route def stop_times_schedule_for(date) - # TODO: .all.first is a weird syntax to do eager loading correctly. Maybe there's a better way? - self_with_eager_loads = GTFS::Realtime::Stop.where(id: id).eager(stop_times: {trip: [:calendar_dates, :route, :shapes]}).all.first - self_with_eager_loads.stop_times.select{|st| st.trip.active?(Date.today)}.sort_by{|st| st.departure_time} + stop_times.includes(trip: [:calendar_dates, :route, :shapes]).select{|st| st.trip.active?(date)}.sort_by{|st| st.departure_time} end def stop_times_for_today stop_times = stop_times_schedule_for(Date.today) stop_time_updates.each do |stu| \ No newline at end of file