Sebastián
DTDrizzle Team
•Created by Sebastián on 8/16/2023 in #help
Select filters for n tables on relational queries
Let's just use the schema from the docs: Users has many Posts
This would give me User 1 with all of their posts:
const res = await db.query.users.findMany({
where: eq(users.id, 1),
with: {
posts: true
}
});
What if I want to retrieve the User with only the posts that have a certain keyword on them
I thought this would work:
const res = await db.query.users.findMany({
where: and(
eq(users.id, 1),
like(posts.content, "%bananas%"),
),
with: {
posts: true
}
});
But apparently that searches for "bananas" on a Users column.
If not possible with relational queries I'd have to use regular selects with Joins and then use Aggregations to present the data like relational queries do.
Any help would be appreciated2 replies
DTDrizzle Team
•Created by Sebastián on 7/29/2023 in #help
Are relational queries supported on mysql?
I'm new to this ORM and I'm having trouble getting relational queries to work.
Normal db.select().from(exTable) works fine, but when I try db.query.exTable.findMany() I get a warning on VSCode: Property 'exTable' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)
36 replies