How to do inserts in many-to-many relations ?
I'm new to Drizzle and I don't really know if my tables relation is correct or not.
Here's the schema:
I chose to use a many-to-many relation because a music can have multiple authors and an author can have multiple music. Is my schema correct ?
Insert in comment
1 Reply
Here's how I handle the insert for now (it's not complete):
I'm using the music metadata.
I'm currently looping over each artist and checking whether they exist. If they don't I'm creating them and I get their ID.
This is where I'm stuck, as there are multiple tables for the relations I don't know in which one I should do the insert and if I'm using the right method. I guess that I need to get the author id and the music id and put them in one of the relation tables but I don't know if I should do that in the loop or outside and if there are risks that doing the insert in a loop could break it.
Do I have the correct way of doing it or is there a better way ? How would you refactor my code ?