unionAll gives TypeError: leftSelect.getSelectedFields is not a function
I'm trying to query 2 collections in the same query as the amount of collections might grow over time that I will check against I would want a scalable way and also use drizzles built in features, so I tryed this:
Note I'm using Payload CMS, so I don't have access to the schema files directly, actually got no clue if its db.schema or db.tables I should use.
Running these queries separately works great, just when I add unionAll I get:
[15:34:20] ERROR (payload): TypeError: leftSelect.getSelectedFields is not a function at /Users/livog/Documents/Projects/Payload.CMS/node_modules/.pnpm/drizzle-orm@0.29.0_pg@8.11.3/node_modules/src/pg-core/query-builders/select.ts:677:42
[15:34:20] ERROR (payload): TypeError: leftSelect.getSelectedFields is not a function at /Users/livog/Documents/Projects/Payload.CMS/node_modules/.pnpm/drizzle-orm@0.29.0_pg@8.11.3/node_modules/src/pg-core/query-builders/select.ts:677:42
Code:
const db = payload?.dbconst drizzle = payload?.db?.drizzleif (!payload || !db || !drizzle || collectionsToCheck.length === 0) return false // This will be checked server side or we don't support it without drizzle.const rows = await unionAll( // @ts-ignore ...collectionsToCheck.map(collection => { const andCondtions = [eq(db.schema[collection]['path'], path)] if (currentCollection !== collection) { andCondtions.push(ne(db.schema[collection]['id'], currentDocId)) } return drizzle .select({ id: db.schema[collection]['id'], path: db.schema[collection]['path'] }) .from(db.tables[collection]) .where( // @ts-ignore // Todo: type checking and(...andCondtions) ) }) )
const db = payload?.dbconst drizzle = payload?.db?.drizzleif (!payload || !db || !drizzle || collectionsToCheck.length === 0) return false // This will be checked server side or we don't support it without drizzle.const rows = await unionAll( // @ts-ignore ...collectionsToCheck.map(collection => { const andCondtions = [eq(db.schema[collection]['path'], path)] if (currentCollection !== collection) { andCondtions.push(ne(db.schema[collection]['id'], currentDocId)) } return drizzle .select({ id: db.schema[collection]['id'], path: db.schema[collection]['path'] }) .from(db.tables[collection]) .where( // @ts-ignore // Todo: type checking and(...andCondtions) ) }) )