Drizzle with multi-file schema not working.

So drizzle itself is working, but i cant make queries with "with" because the relations seem off. but with innerJoins it works and also when i put it in the schema.ts file it works. pretty sure i am configuring something not right in my index.ts file in my db folder (screenshot attached). any help is appreachiated!
No description
Solution:
in case anyone has a similar question: this is my index.ts file now that seems to work
No description
Jump to solution
13 Replies
Juraj98
Juraj98•5mo ago
How do your individual schema files look? My guess is that you're only importing the table and not the relations. Try import * as name1 from "file" and then deconstruct that object into schema schema: { ...name1, ...name2 }
LukasGaeb
LukasGaeb•5mo ago
thats one of the schema files. the others are similar
LukasGaeb
LukasGaeb•5mo ago
No description
Juraj98
Juraj98•5mo ago
Yeah, you're only importing the deals table schema and not the dealsRelations, so drizzle doesn't know about it.
LukasGaeb
LukasGaeb•5mo ago
but in the database the realtions are correct... should correlate right? import * as x doesnt seem to work... intellisense is really confused and cant suggest any tables anymore i will try to import the relations extra
Juraj98
Juraj98•5mo ago
No, the relations declared using relations are only for drizzle. There is nothing like relations in normal SQL, so the joins work anyway. (Technically foreign keys are SQL relations, but they don't affect joins)
LukasGaeb
LukasGaeb•5mo ago
but the db model looks fine with the relations... thats what confused me
No description
Juraj98
Juraj98•5mo ago
This graph is based on SQL foreign key relations. You declared those with .references() in the table schema. But relations() function is for drizzle.
LukasGaeb
LukasGaeb•5mo ago
ahhh okay thanks!! intellisense is not as confused anymore... seems to work. thank you so much!
Juraj98
Juraj98•5mo ago
Btw, I think you can replace default(sql'CURRENT_TIMESTAMP') with .defaultNow().
LukasGaeb
LukasGaeb•5mo ago
nice thanks!
Juraj98
Juraj98•5mo ago
🫡
Solution
LukasGaeb
LukasGaeb•5mo ago
in case anyone has a similar question: this is my index.ts file now that seems to work
No description
Want results from more Discord servers?
Add your server