© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
1 reply
roguesherlock

infer model with relations

is possible to infer model along with all its relations?
Like if I have

projects and projectsRelations which includes tasks
can I create a type Project that includes tasks?

export const projects = mysqlTable(
  "projects",
  {
    id: serial("id").primaryKey(),
    name: varchar("name", { length: 256 }),
  }
)

export const projectsRelations = relations(projects, ({ many }) => ({
  tasks: many(tasks),
}))


export type Project = InferModel<<projects-with-its-relations>?>

// currently I just do
export type Project = InferModel<typeof projects> & {tasks?: Task[]}
export const projects = mysqlTable(
  "projects",
  {
    id: serial("id").primaryKey(),
    name: varchar("name", { length: 256 }),
  }
)

export const projectsRelations = relations(projects, ({ many }) => ({
  tasks: many(tasks),
}))


export type Project = InferModel<<projects-with-its-relations>?>

// currently I just do
export type Project = InferModel<typeof projects> & {tasks?: Task[]}
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

can you Infer relations?
Drizzle TeamDTDrizzle Team / help
3y ago
Infer typescript type from table with relations
Drizzle TeamDTDrizzle Team / help
2y ago
Proper way to infer update model?
Drizzle TeamDTDrizzle Team / help
13mo ago
help with relations
Drizzle TeamDTDrizzle Team / help
2y ago