© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•16mo ago
TGTGamer

Where based on relationships?

I'm trying to query the database for a specific values which fit a filter based on relationships. Is this possible?

const result = yield* Effect.tryPromise(
            () => db.query.productUniqueId.findMany(
                {
                    // ...options,
                    where:
                        (
                            productUniqueId,
                            { and, eq }
                        ) => (
                            and(
                                eq( productUniqueId.type, type ),
                                eq( productUniqueId.product.outlets.outlet.id, outletId),
                            )
                        ),
                    with: {
                        product: {
                            columns: {},
                            with: {
                                outlets: {
                                    columns: {},
                                    with: {
                                        outlet: {
                                            columns: {
                                                id: true,
                                                name: true
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            )
        )
const result = yield* Effect.tryPromise(
            () => db.query.productUniqueId.findMany(
                {
                    // ...options,
                    where:
                        (
                            productUniqueId,
                            { and, eq }
                        ) => (
                            and(
                                eq( productUniqueId.type, type ),
                                eq( productUniqueId.product.outlets.outlet.id, outletId),
                            )
                        ),
                    with: {
                        product: {
                            columns: {},
                            with: {
                                outlets: {
                                    columns: {},
                                    with: {
                                        outlet: {
                                            columns: {
                                                id: true,
                                                name: true
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            )
        )


In the above example I got the
TS2551: Property product does not exist on type
TS2551: Property product does not exist on type
- so I switched to filtering after getting the data from the database, but wanted to see if there was a way to handle this in the query
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Add conditions on relationships
Drizzle TeamDTDrizzle Team / help
3y ago
Traversing many to many relationships with sorting and filtering based on the related table.
Drizzle TeamDTDrizzle Team / help
12mo ago
One-way Relationships
Drizzle TeamDTDrizzle Team / help
17mo ago
feedback on my database design (specially with relationships)
Drizzle TeamDTDrizzle Team / help
2y ago