Delete Many
The deleteMany method removes multiple records that match the provided
filter. It runs inside a transaction to guarantee data integrity.
Purpose
The deleteMany method is used to delete all records that match a specific condition. It is optimized for bulk deletions and ensures atomic operations through transactions.
Parameters
- where — Required. Conditions used to filter which records will be deleted.
Return Value
Returns the number of deleted rows.
Example: ["count" => 4]
Error Handling
- Throws an Exception if the database operation fails.
- Ensures transaction rollback on errors for data safety.
Example Usage
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$deletedRows = $prisma->user->deleteMany([
'where' => ['roleId' => 1],
]);
echo "<pre>";
echo "Deleted rows: " . print_r($deletedRows, true);
echo "</pre>";