how to create relatedWords relation for each words using drizzle. | DRIZZLE | SQL |
Hi folks,
I'm building an online Turkish dictionary using t3 stack with drizzle. I want every word can have related words so that I can show them in related words section when a word searched.
What I tried is to create another table called
relatedWords
that includes an id
and relatedWordId
in order to create many-to-many relationship between word and relatedWords.
Here's what I tried with drizzle schemas and relations:
Drizzle studio throws this error: Error: There is not enough information to infer relation "__public__.relatedWords.wordsToRelatedWords"
It's been a while since I created SQL relationships last time and I've never done such a relationship like this. Thanks in advance for any help!2 Replies
I think you need to change this:
If you want to make it self referecing, which probably is a good idea you can just get rid of the relatedWords table and have word1Id and word2Id (no better name in my head rn haha) and use that instead
Would simplify your code a lot
Not sure but that should work, I didnt test
I made this changes but it's still throwing the same error
a word can have multiple related words, like it can be 2, 3, 10 or more. i guess word1Id and word2Id wouldn't work in this cases.
one second thought, what if I just put the related words as an array of strings or without any relationship ? is it too bad idea thank you for your time and answer