© 2026 Hedgehog Software, LLC

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

Conditional Select in M2M findMany Type Inference

hey there, I'm adding a method that allows the user to either get a list of objects, and sometimes get related objects al well (members). it works fine function-wise - but for some reason, the addition of the ternary doesn't give me any type hints. I'd assume it'll add them conditionally...

Is this a bug? am I missing anything?

here is my code's paraphrase:
return db.query.projects.findMany({
    columns: {
        id: true
    },
    with: {
        membersMapping: {
            columns: {
                memberId: true,
            },
            //** this makes the type inference crazy!
            with: withMembers ? { member: { columns: { name: true, age: true } } } : {}
        }
    }
})
return db.query.projects.findMany({
    columns: {
        id: true
    },
    with: {
        membersMapping: {
            columns: {
                memberId: true,
            },
            //** this makes the type inference crazy!
            with: withMembers ? { member: { columns: { name: true, age: true } } } : {}
        }
    }
})
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

findMany conditional select one-to-one relation
Drizzle TeamDTDrizzle Team / help
2y ago
conditional select return wrong type
Drizzle TeamDTDrizzle Team / help
2y ago
Select in nested findMany query ?
Drizzle TeamDTDrizzle Team / help
2y ago
withPagination type inference
Drizzle TeamDTDrizzle Team / help
2y ago