Forum: Ruby on Rails Time table models and querying approach

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
167a3b5582230623eb94e638133122ec?d=identicon&s=25 Kris (Guest)
on 2006-03-22 14:07
I doing an app to allow people to search bus time tables by bus stop and
time.

My models are:

Providers -> Services -> Runs -> Stops <- Stations

Key:

"->" denotes a one to many
Providers = Bus companies
Services = the bus number
Runs = Columns on a bus time table
Stops = Cells on a bus time table, basically a time
Stations = Rows on a bus time table

StationA    10:00  10:50  11:30
StationB    10:05  10:55  11:34
StationC    10:15  11:10  11:44
StationD    10:17  11:12  11:52
StationE    10:22  11:19  12:00

My question is to do with the model setup and how to search it since the
query is quite complex.

Model/Tables:

I was considering dropping the Stations table and making Stops
acts_as_taggable. I assuming tags are simply labels which are shared
across models? Also can you add additional information to a tag ie.
extra fields?

Query:

At the moment Im trying to get my head round exactly how to tackle this!
Do I have multiple find's or one big ruby style find.
Basically the user is going to specify a start and end station and a
start and end time.

So first of all I need to find all runs that have stops that link to the
start and end stations. The end station must be after the start station.

Then I need to check to see if the times of those stops fall an hour
either side of the times specified by the user.

Does this sound right? Is there an easier way to approach this problem?

Many thanks, Kris.
This topic is locked and can not be replied to.