I'm used to writing my own SQL queries and I'm trying to get used to the whole ORM thing that seems to be so popular nowadays.
Here's the query:
SELECT * FROM routes WHERE route_id IN (
SELECT DISTINCT t.route_id FROM stop_times AS st
LEFT JOIN trips AS t ON st.trip_id=t.trip_id
WHERE stop_id = %s
)
where %s is an integer.
I'm using Django's default ORM. What's the most pythonic way to do this?
Some background info: The DB I'm using is from a GTFS (Google Transit feed specification). This query is supposed to get a list of every route
that goes through a particular stop
, however the info linking these is in the trips
table.
This query works just fine for me, so the only reason I'm asking is to learn.
Thanks!