Multiple relations
Let's say I have this relationship from message to users:
And I'd like to add a relation from user to messages, by the sender. I thought of doing this:
But it errors out, Error: There is not enough information to infer relation "UserTable.messages"
I assume I need to tell it what relation messages is linked with, but how do I go about doing that? The docs provide no information about this.
6 Replies
You have to name the relations
@yuval59
btw. Drizzle has a very good typescript DX, you can always check if there are some fields you're missing by looking at autocompletion 😉
that's how i learned about them haha
I see, I did look at the autocomplete for the many() thing but I didn't think of doing it to the one() config, my bad
I do think this stuff should probably be better explained in the docs tho, seems like a pretty obvious thing to need ¯\_(ツ)_/¯
yeah they should write about them in the docs
i also struggled with configuring those relations but i had multiple many-to-many ones
mmmmm that sounds like fun
Like, if you had multiple one-to-one relations this wouldn't be a problem (Because of the fields + references thing)
yeah, i had to use the relationName in 3 places and debug where it should be lol
Anyways, thank you very much for the help!
It works, so I'm gonna close the thread