DT
Drizzle Team•2mo ago
Fadi

Extending Relations

I have a nextjs project with supabase as backend database. I introspected the auth table since I created a several tables that extend the auth.users table. The generated file has many relations already setup. When I try to add my own relations in the schema file, it seems to remove the types and the queries are no longer typed, i.e the response only contains the auth.users columns and not the related tables even when using the with keyword. My thoery is creating two separate relations on the same table is messing things up. So my question is that is there a way to extend the relation in the generated file since I would prefer not to touch this file?
4 Replies
rphlmr âš¡
rphlmr ⚡•2mo ago
👋 It's totally fine to edit the relations in the schema.ts. These relations (with relations()) are in-app relations and are not involved in any SQL.
Fadi
Fadi•2mo ago
True but wouldn't running introspect again re write the file? The relations are generated in a separate file from the schemas. One of these relations would be
export const usersInAuthRelations = relations(usersInAuth, ({ many, one }) => ({
mfa_factorsInAuths: many(mfa_factorsInAuth),
sessionsInAuths: many(sessionsInAuth),
identitiesInAuths: many(identitiesInAuth),
one_time_tokensInAuths: many(one_time_tokensInAuth),
// companyUser: one(companyUsers, { fields: [usersInAuth.id], references: [companyUsers.id] }),
// applicant: one(applicants, { fields: [usersInAuth.id], references: [applicants.id] }),
}));
export const usersInAuthRelations = relations(usersInAuth, ({ many, one }) => ({
mfa_factorsInAuths: many(mfa_factorsInAuth),
sessionsInAuths: many(sessionsInAuth),
identitiesInAuths: many(identitiesInAuth),
one_time_tokensInAuths: many(one_time_tokensInAuth),
// companyUser: one(companyUsers, { fields: [usersInAuth.id], references: [companyUsers.id] }),
// applicant: one(applicants, { fields: [usersInAuth.id], references: [applicants.id] }),
}));
I preferably would want to add the companyUser and application relation in my own schema files since this generated file would be over written if I run introspect the database again.
rphlmr âš¡
rphlmr ⚡•2mo ago
You should introspect once (or maybe you have a specific use case?). Soon Drizzle wants to separate schema and relations into separate files, so maybe keep it like that. https://arc.net/l/quote/osjfnuft
Want results from more Discord servers?
Add your server