Unable to infer relationship between tables
I wanted to try out Turso with Drizzle and am feeling stupid here but I am following the docs and I just cannot get this to work
My set up
My schema
Error:
What am I doing wrong here? I have the option of creating a join/through table but the docs suggest that isn't needed. So how can I correctly infer these relationships?
10 Replies
i have the same issue, i came by to see if there were answers lol,
You have not created any way to link those two tables together. The many-to-many example in the Drizzle docs has an additional table that maps the two entities to each other. See below:
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
In your case:
For my case, i've re-worked the relations like you suggested here and I'm getting the relations from the many to many (groupId, userId from the example) as expected but i dont know how to get the list of groups from the relationship when i query with "findMany" and
I had done this before but when inserting, I couldn't see the relation, so just assumed I was doing something wrong 😂 . How would i insert something into the albums table and link the artist?
When you have an entry in your albums and artists tables you need to link, you'd insert a record in the artistsToAlbums table with the id for each of them.
Yeah, that felt strange to me coming from prisma where I can just create an album and
connect
to an artist. I guess it was coming out of that mindset. Thanks for your help.Yeah, that's just how many-to-many relationships work. You use an intermediary table to form the relationships.
For one-to-many, for example one artist to many albums, you'd add the artistId column to the albums table.