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
selectis provided,omitis merged with all default model fields and removes the specified ones. - If
selectis used,omitoverrides 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
omitto remove sensitive fields likepassword,authToken, or system metadata. - Apply
omitwhen returning full model objects but want fine control over exclusions. - If you're using
select, remember thatomitwill still apply and remove matching fields. - Do not use
omitto filter nested fields insideinclude; it only affects the root-level model.