My CRUD application's data models:
What is the proper way to set up the FilmGroup model? It has a one-to-many relationship with Film and a one-to-one relationship with FilmOrder.
I need both FilmOrderID and FilmOrder to associate the FilmOrderID with this model, but also want easy access to the associated FilmOrder since I render all data to the user.
How do I simplify the FilmGroup model so it does not need FilmOrderID and a reference to a FilmOrder object? How to map FilmOrder *FilmOrder
to a database field? I want to use the same struct for the database model and to display the object.
...the FilmGroup model. It has a one to many relationship with Film, and a one to one relationship with FilmOrder.
One-to-one relationships are suspect and difficult to enforce.
Here's a simpler model assuming a Film can only be in one FilmGroup, and a FilmOrder can only be for one FilmGroup. Film and FilmOrder both reference FilmGroup.
Film -> FilmGroup <- FilmOrder
If a Film can be in more than one FilmGroup, you'd put the FilmGroup_Film join table back, but FilmOrder would still refer to FilmGroup.
Film <- FilmGroup_Film -> FilmGroup <- FilmOrder
Both of these have the possibility that a FilmGroup could be the subject of multiple FilmOrders. If you want to make it one-to-one, make FilmOrders.film_group_id unique.
create table if not exists
. It seems convenient, but what will happen is you'll create the table, change your create table if not exists
statement, run your script again, and then spend hours trying to figure out why it doesn't work.