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
👋 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.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
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.
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
https://discord.com/channels/1043890932593987624/1263501087055413294/1263515325388034188
This is how I manage that, if it can help