Files
klz-cables.com/.pnpm-store/v10/files/6a/b1f6474341481b236abcaa512e639acb8c1a61b3471ff04f699f927aaf3a03255d22622072677c4131aafe331abd30cfcc52b601bdb79986f005a1dbc03f73
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

46 lines
1.7 KiB
Plaintext

import { inArray } from 'drizzle-orm';
import toSnakeCase from 'to-snake-case';
import { findMany } from './find/findMany.js';
import { buildQuery } from './queries/buildQuery.js';
import { getTransaction } from './utilities/getTransaction.js';
export const deleteMany = async function deleteMany({ collection, req, where: whereArg }) {
const collectionConfig = this.payload.collections[collection].config;
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
const table = this.tables[tableName];
const { joins, where } = buildQuery({
adapter: this,
fields: collectionConfig.flattenedFields,
locale: req?.locale,
tableName,
where: whereArg
});
let whereToUse = where;
if (joins?.length) {
// Difficult to support joins (through where referencing other tables) in deleteMany. => 2 separate queries.
// We can look into supporting this using one single query (through a subquery) in the future, though that's difficult to do in a generic way.
const result = await findMany({
adapter: this,
fields: collectionConfig.flattenedFields,
joins: false,
limit: 0,
locale: req?.locale,
page: 1,
pagination: false,
req,
select: {
id: true
},
tableName,
where: whereArg
});
whereToUse = inArray(table.id, result.docs.map((doc)=>doc.id));
}
const db = await getTransaction(this, req);
await this.deleteWhere({
db,
tableName,
where: whereToUse
});
};
//# sourceMappingURL=deleteMany.js.map