Select Fields
Meet the next generation of documentation. AI-native, beautiful, out-of-the-box, and built for developers and teams.
Selecting Specific Fields with select
The select parameter allows you to specify exactly which fields
to include in the result. This improves performance and enhances security by returning only the data you need.
- Accepts an associative array where each key is a field name and the value is
trueto include it. - Supports nested selections for related models.
- Cannot be used together with
include. - Automatically excludes all fields not marked as
true.
Example Usage: Basic Field Selection
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$users = $prisma->user->findMany([
'select' => [
'id' => true,
'name' => true,
'email' => true
]
]);
echo "<pre>";
print_r($users);
echo "</pre>";
Example Usage: Nested Field Selection
$users = $prisma->user->findMany([
'select' => [
'id' => true,
'name' => true,
'profile' => [
'select' => [
'bio' => true
]
]
]
]);
Best Practices
- Use
selectto reduce response payloads and improve performance. - Avoid returning unnecessary or sensitive data.
- Prefer explicit field selection instead of returning all fields by default.
- Do not use
selectwithinclude—choose one strategy.