Sub-field Filtering example
In the 0.28.0 update that removed relation filters, the changelog suggests:
https://github.com/drizzle-team/drizzle-orm/releases/tag/0.28.0
If you have used those fields in the where callback before, there are several workarounds: 1. Applying those filters manually on the code level after the rows are fetched; 2. Using the core API.I'd rather not apply the filter in the code level. Could someone provide an example of "2. Using the core API." to achieve a basic top level filter based on a sub-field property?
GitHub
Release 0.28.0 · drizzle-team/drizzle-orm
Breaking changes
Removed support for filtering by nested relations
Current example won't work in 0.28.0:
const usersWithPosts = await db.query.users.findMany({
where: (table, { sql }) => (...
2 Replies
The core API is using
db.select().from(table).where(...)
instead of db.query.table.findFirst()
.
I'd imagine in this case, you'd want to have foreign keys set up instead of Drizzle's RQB relations, then use joins, referencing those joins in your where query?
https://orm.drizzle.team/docs/joins
If you wanted to get all posts where the author's name is "Joe" it might be something like this:
gets you
Let me know if that makes sense!Joins [SQL] – DrizzleORM
Drizzle ORM | %s
Ah, got it. Thank you so much @Noahh !