© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
4 replies
jakeleventhal

How to define type of table with all relations included?

Say I have a a table users and a user has many posts, so I define a relationship as shown in the docs

If I want to define a type that is "user with posts" that would be the result of:
await db.query.user.findFirst({ with: { posts: true } });
await db.query.user.findFirst({ with: { posts: true } });

the type of this would be something like
type UserWithPosts = (typeof users._.inferSelect) & {posts: Array<typeof posts._.inferSelect>}
type UserWithPosts = (typeof users._.inferSelect) & {posts: Array<typeof posts._.inferSelect>}


Is there a cleaner way to define that where all the relations are just included and automatically inferred?
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

how to define array relations ?
Drizzle TeamDTDrizzle Team / help
3y ago
how to define relations for friendship?
Drizzle TeamDTDrizzle Team / help
2y ago
Filter included relations
Drizzle TeamDTDrizzle Team / help
2y ago
Infer typescript type from table with relations
Drizzle TeamDTDrizzle Team / help
2y ago