Many-to-Many Relationships the Redwood Way™️

So assuming you could get past the migrate and up steps, here’s where we stand:

If you don’t care about generators

If you just want to write the GraphQL and services manually, you should be able to go ahead and do that! Check out the Apollo docs for writing the queries in your components/cells (client docs) and the SDLs (server docs). For the services check out the Prisma docs for how to drill down through relationships in your models.

If you do care about the generators

We don’t currently know what to do about composite keys, the @@id([postId, categoryId]) bit. Are you sure you don’t want to just create an id column for that table, that you just ignore? That’s what Rails would do! :slight_smile: It makes everything so much simpler when each table just has a single id column…

There also may be an issue with the plural table name CategoriesOnPosts. For a while Prisma recommended singular model names and would create singular syntax for accessing them like db.post.category even though it was a collection of categories. When we wrote the generators we used that same “make everything singular” logic. They’ve since removed that and now you can make your model singular/plural and the relationship object syntax will match whatever you use, but we haven’t had a chance to update the generators.

1 Like