Dada
Dada
DTDrizzle Team
Created by Dada on 12/14/2024 in #help
Type generation for relations
Hi all. I'm doing my first project with Drizzle. I'm using InferSelectModel to type my tables, which is working well, but now I also want to generate a type for a row that I'll fetch with relations. So for example, I have this relation:
export const discordMessageRelations = relations(discordMessage, ({one, many}) => ({
parentMessage: one(discordMessage, {
fields: [discordMessage.parentId],
references: [discordMessage.id],
relationName: 'childMessage',
}),
childMessage: many(discordMessage, {relationName: 'childMessage'}),
}))
export const discordMessageRelations = relations(discordMessage, ({one, many}) => ({
parentMessage: one(discordMessage, {
fields: [discordMessage.parentId],
references: [discordMessage.id],
relationName: 'childMessage',
}),
childMessage: many(discordMessage, {relationName: 'childMessage'}),
}))
Right now I'm doing this:
export type SelectDiscordMessage = InferSelectModel<typeof discordMessage>
export type SelectDiscordMessageWithChildren = SelectDiscordMessage & {childMessage: SelectDiscordMessage[]}
export type SelectDiscordMessage = InferSelectModel<typeof discordMessage>
export type SelectDiscordMessageWithChildren = SelectDiscordMessage & {childMessage: SelectDiscordMessage[]}
Is there a way to automatically get an inferred type that includes relations?
1 replies