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!
Solution:Jump to solution
in case anyone has a similar question: this is my index.ts file now that seems to work
13 Replies
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 }
thats one of the schema files. the others are similar
Yeah, you're only importing the
deals
table schema and not the dealsRelations
, so drizzle doesn't know about it.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
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)but the db model looks fine with the relations... thats what confused me
This graph is based on SQL foreign key relations. You declared those with
.references()
in the table schema. But relations()
function is for drizzle.ahhh okay thanks!!
intellisense is not as confused anymore... seems to work. thank you so much!
Btw, I think you can replace
default(sql'CURRENT_TIMESTAMP')
with .defaultNow()
.nice thanks!
🫡
Solution
in case anyone has a similar question: this is my index.ts file now that seems to work