"There is not enough information to infer relation" with many to many query
Hey there,
I'm encountering the following error message when trying to do a many to many query:
ERR error: There is not enough information to infer relation "locations.tags"The query: The schema: Not sure what I'm doing wrong here. I tried a few variations of the
findMany
query and naming relations differently but nothing worked so far. Any idea what's wrong? Thanks!2 Replies
First, your schema is wrong. The intermediate table (the one, that links two tables for many-to-many relationship) can only have one to one reference with the ones it links. In your casez locationsToTagsRelations will have one(tags) & one(locations).
Then, if you want to get all the locations with tags, you can use joins / with in findMany on your intermediate table
That last
locationsToTagsRelations
relation bit was initially missing and I added it because I read that relations have to be made on both sides. I missed that I defined it as many
in there instead of one
. Simply changing it to the correct relation type worked right away, didn't have to change the query. Here's the updated code for reference:
Thank you for the help!