Hi, this is a very learning-oriented question but I’m hoping to solidify my understanding of relationships between tables as I build my app. Consider the following two hypothetical tables, “Ride” and “Person”:
The business here is one that provides rides to medical patients. For each ride, there is a Driver, who actually drives the car the patient is being transported in, and a Dispatcher, who receives the call requesting a ride and coordinates the operation remotely. In some cases, due to operational logistics, it is possible to have a second driver or dispatcher (e.g. the patient needs to be handed off mid-ride).
The schema is such that there is a table tracking all of the rides and another table that has all of the people, who in this case are all employees and are either Drivers or Dispatchers.
When I think about this from a layperson’s perspective, and disregarding the possibility of the second driver/dispatcher, I think of these as 1:1 relationships. A ride has a single main Driver, which is relatable to the Person table. It also has a single main Dispatcher, which is relatable to the Person table. When I add the possibility of a second driver/dispatcher these are still just 1:1 relations in my head, because they’re all distinct people in distinct roles.
I suspect that in database-world these are many:many relationships though. Is the optimal way to set this up to follow the procedure reviewed here?
If so, how do I track the person type as part of the relationship? In the example of students and courses, all students and all courses are essentially fungible. In my case though the people being assigned to the ride are fundamentally different. One person is the primary Driver, another person is the primary Dispatcher. In some cases there is also a secondary driver and secondary dispatcher. This is not just a collection of fungible items in an order or students in a class.
Can you let me know the best way to structure the schema in this type of situation and how to establish the relations in a way that preserves this distiction between Person “type” and whether they’re the main or backup entity?