drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: predefined filter on the `through` table
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
[RQB v2](https://orm.drizzle.team/docs/relations-v1-v2) does support predefined filters, but it is partially supported on many-to-many relations. For example:
```ts
import { and, eq, lte } from 'drizzle-orm';
and(
eq(userTable.verified, true), // this can be predefined
lte(userToGroups.addedAt, new Date()), // but not this
);
```
```ts
import { defineRelations } from 'drizzle-orm';
import * as schema from './schema';
export const relations = defineRelations(schema, (r) => ({
groups: {
verifiedUsers: r.many.users({
where: { verified: true },
// predefined filter is available on `user` only
// cannot add predefined filter for `usersToGroups`
from: r.groups.id.through(r.usersToGroups.groupId),
to: r.users.id.through(r.usersToGroups.userId),
}),
},
}));
Contributor guide
Research direction
Start with the RQB v2 relations documentation and the defineRelations example in the issue. Trace how the existing where filter on r.many.users is applied, then inspect how the through relation is handled for many-to-many queries. Done means a predefined filter can also be declared for usersToGroups and is applied in the generated query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100