ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข13mo agoโ€ข
10 replies
dayo

Need help inferring types of nested model

I'm new to drizzle, so obvious skill issue here, but how can I infer types from models with specific relations selected?

I know of
InferSelectModel
InferSelectModel
but I don't see a way to include relations.

Ideally I'd want to infer the type i get from something like this:

  async userById(id: string) {
    const user = await this.db.query.users.findFirst({
      where: eq(users.id, id),
      with: {
        teamMemberships: {
          columns: {
            role: true,
            createdAt: true,
          },
          with: {
            team: true,
          },
        },
      },
    });
    return user;
  }
  async userById(id: string) {
    const user = await this.db.query.users.findFirst({
      where: eq(users.id, id),
      with: {
        teamMemberships: {
          columns: {
            role: true,
            createdAt: true,
          },
          with: {
            team: true,
          },
        },
      },
    });
    return user;
  }
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

Inferring types for nested objects
Drizzle TeamDTDrizzle Team / help
2y ago
Inferring Types from Schema?
Drizzle TeamDTDrizzle Team / help
13mo ago
Best practices for inferring types in queries?
Drizzle TeamDTDrizzle Team / help
12mo ago
types from nested relational queries
Drizzle TeamDTDrizzle Team / help
3y ago