UpdateManyAndReturn

The updateManyAndReturn method updates multiple records that match a given filter and returns the updated entries with optional field selection.

Purpose

The updateManyAndReturn method performs bulk updates on multiple records that match the where filter and returns the updated results. It supports shaping the output using select, include, or omit.

Parameters

  • where — Required. Conditions to match the records to update.
  • data — Required. Field-value pairs to update.
  • select — Optional. Specifies which fields to return.
  • include — Optional. Includes related models in the result.
  • omit — Optional. Excludes specific fields from the result.

Return Value

Returns an array of updated records. If no records match, an empty array is returned.

Exception Handling

  • Throws Exception if where or data is missing.
  • Throws LogicException when select and include are used together.
  • Throws InvalidArgumentException for invalid enum values.
  • Throws Exception if no valid scalar fields exist in data.
  • Runs inside a transaction and rolls back on failure.

Features

  • Bulk updates based on advanced filtering.
  • Returns updated rows using select, include, or omit.
  • Automatically updates isUpdatedAt timestamp fields.
  • Validates enums and coerces data types.
  • Safe transaction-based operation.

Example Usage

use Lib\Prisma\Classes\Prisma;

$prisma = Prisma::getInstance();

$users = $prisma->user->updateManyAndReturn([
    'where' => [
        'role' => ['equals' => 'User']
    ],
    'data' => [
        'status' => 'active'
    ],
    'select' => [
        'id' => true,
        'name' => true,
        'status' => true
    ]
]);

echo "<pre>"; print_r($users); echo "</pre>";

    

Behavior When No Records Match

$users = $prisma->user->updateManyAndReturn([
    'where' => [
        'status' => ['equals' => 'non-existent']
    ],
    'data' => [
        'status' => 'archived'
    ]
]);

// Output: []
print_r($users);