One to Many with composite primary key?
I am working on a transit-related application (not super important, but may provide context for mental model of the below tables). I am importing data that is conforming to the
gtfs
spec, so I am not doing any pre/post processing of the data provided in a collection of csv files, I am just importing them straight into a database.
I have a table of "Shapes" (which really should be though of as points (lat/lon) along a bus trip). The primary key is a combination of the id
and sequence
fields.
I also have a table of "Trips" which contains a shape_id
in the table. Different trips may have the same shape_id
(e.g. think of trips happening at different times).
Because the Shapes
table has a composite primary key, I cannot figure out how to create a relation from the Trips
table to successfully query the shape rows for a particular trip.
While it's true that each shape_id has many trips, I would probably never need to look that up, but I can still say something like
But where I'm running into trouble is how to create the relationship for Trips
to get the shapes[] results
I suppose in the worst case I would have to manually create a many-to-many join table between trips and shapes and use the typical many-to-many pattern, but I would love to avoid that if there is some mechanism to achieve the above.
The join table would essentially be
with no repeating trip_id
(which isn't much of a join table).
Anyway, I know this was a lot of text, but I hope it is sufficient information to explain what I am trying to accomplish.0 Replies