Omitting Fields with omit
The omit
parameter allows you to exclude specific fields from the result set. This is useful when you want to return most fields but intentionally hide certain ones (e.g., passwords, tokens).
- Accepts an associative array where each key is the field name and the value is
true
. - If no
select
is provided,omit
is merged with all default model fields and removes the specified ones. - If
select
is used,omit
overrides it and removes matching keys from the final output. - Cannot be used to omit fields from related models included via
include
.
Example Usage: Omitting Fields
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$users = $prisma->user->findMany([
'omit' => [
'password' => true,
'authToken' => true
]
]);
echo "<pre>";
print_r($users);
echo "</pre>";
Example Usage: Combining select
with omit
$users = $prisma->user->findMany([
'select' => [
'id' => true,
'name' => true,
'email' => true,
'password' => true
],
'omit' => [
'password' => true
]
]);
Best Practices
- Use
omit
to remove sensitive fields likepassword
,authToken
, or system metadata. - Apply
omit
when returning full model objects but want fine control over exclusions. - If you're using
select
, remember thatomit
will still apply and remove matching fields. - Do not use
omit
to filter nested fields insideinclude
; it only affects the root-level model.