Nested where filter, how to not include empty

The following almost works
const query = db.query.productionItem.findMany({
with: {
itemStages: {
where: eq(itemStage.crew_id, input.crew_id),
},
},
});
const query = db.query.productionItem.findMany({
with: {
itemStages: {
where: eq(itemStage.crew_id, input.crew_id),
},
},
});
I get only those productionItems with itemStage of particular crew_id, but I also get those with no itemStage's so query result has itemStages: []. How do I only include if crew_id equal and productionItem has itemStage
Angelelz
Angelelz193d ago
The where that you have only filters the itemStages You need a where for the productionItems For that to work, you either use a subquery in the where or you have to turn to the regular crud API: db.select
Nxia618
Nxia618193d ago
Not following what " use a subquery in the where " means?
Angelelz
Angelelz193d ago
Take a look at this thread: https://discord.com/channels/1043890932593987624/1166190702984708126 There are several examples in there for a very similar query In this message is the subquery I was talking about: https://discord.com/channels/1043890932593987624/1166190702984708126/1166201121107345478
Nxia618
Nxia618193d ago
thanks, I'll take a look
Want results from more Discord servers?
Add your server
More Posts
is placeholder in prepare statements deprecated!??```typescript const courses = db.query.userCourses .findMany({ where: eq(placeholder("userId")SQLite json_eachHi. I wandted to use the json_each function in sqlite, but I dont think the query is building correcForeign key truncated for being too long?Hi, I have multiple warnings / notices: `{ severity_local: 'NOTICE', severity: 'NOTICE', codedrizzle-zod with custom typesI have defined opaque types in my application and have implemented those in the drizzle schema (awesUsing transactions in automated testing like JestI have a testing set-up as follows: 1. Start postgres container 2. Apply migrations to db 3. Jest tTypeScript complaining about using a spread operator in partial select queryTypeScript complaining about me using a spread operator in partial select query. I have the followiUnable to read error message when inserting withdb.insert().values()Hey there, i am using visual studio code and am developing with nuxt3. I am trying to insert an objehow to add new driver to drizzle?what is the procedure of adding a new driver to drizzle orm?`drizzle-kit --custom` is not giving me a blank migration fileI'm doing the following: ```sh drizzle-kit generate:pg --custom ``` But it's not giving me a blankNo id returned (mysql2)``` async function create(data: NewBusiness) { return client.insert(business).values(data) } ``` Studio when using Turso `Error: Cannot find module 'better-sqlite3'`Error when trying to start Studio and push `Error: Cannot find module 'better-sqlite3'`[BUG]: React Hook Form doesn't submit when using drizzle-zod to create schemes to use in zodResolverWhen using `drizzle-zod` to generate schemas from database schemas and using them in the `useForm` rAppending SQL chunks to a queryHey everyone, I'm trying to see if there is a way where I can build SQL queries conditionally (basedPostgresjs with Neon giving connnection refusal errorI am unable to connect to my neon database. I tried using `postgresjs` and the `neon serverless` drierror: column "id" cannot be cast automatically to type uuidim using drizzle, and this is my schema: ```typescript export const tags = pgTable("tags", { id: uinArray() using sql`` operator in JS and PostgresHey, how do I use sql operator with arrays in JS? ```javascript const array = [1,2,3]; const sqlQuerUnable to infer relationI have the following tables and relations: ```javascript export const platforms = pgTable('platformsmigrate with node-postgresI had migration working well with postgresjs but need to switch to node-postgres for other reasons.