Selecting Specific Fields with select

The select parameter allows you to specify exactly which fields to include in the result. This improves performance and security by returning only the necessary data.

  • Accepts an associative array where each key is a field name and the value is a boolean (true to include).
  • Can be used with nested selections for related models.
  • Cannot be used at the same time as include.
  • Automatically excludes 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 select to reduce response payloads and improve performance.
  • Avoid returning sensitive or unnecessary fields.
  • Prefer explicit field selection over returning all data by default.
  • Do not use select with include—choose one or the other.