© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
12 replies
Jokerz

can we filter by a prop on a relation during a query?

eg. watch has watch brands + watch families as relations

if i wanted to search across watch name, watch brand name + watch family name should that be possible?

current query just using watch name

const items = await ctx.db.query.watch.findMany({
            ...withCursorPagination({
              limit: 10,
              cursors: [[schema.watchBrand.name, "desc", cursor]],
            }),
            where: and(
              like(schema.watch.name, `%${input.name}%`),
              notInArray(schema.watch.id, usersWatches),
            ),
            with: {
              watchBrand: true,
              watchFamily: true,
            },
          });
const items = await ctx.db.query.watch.findMany({
            ...withCursorPagination({
              limit: 10,
              cursors: [[schema.watchBrand.name, "desc", cursor]],
            }),
            where: and(
              like(schema.watch.name, `%${input.name}%`),
              notInArray(schema.watch.id, usersWatches),
            ),
            with: {
              watchBrand: true,
              watchFamily: 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

Filter items by field on relation using query format
Drizzle TeamDTDrizzle Team / help
6mo ago
Ordering by relation in relational query
Drizzle TeamDTDrizzle Team / help
3y ago
Complex filter on query.
Drizzle TeamDTDrizzle Team / help
11mo ago
Can't filter using 'query' when relation is one to one
Drizzle TeamDTDrizzle Team / help
3y ago