Every

Filter parent records where all related records match the given condition.

What Does every Do?

The every keyword filters a parent record when all related records satisfy the provided conditions. Important: If a parent record has no related records, the condition is considered true automatically.

Supported Operations

  • findMany
  • findFirst
  • findFirstOrThrow
  • findUnique
  • findUniqueOrThrow
  • aggregate
  • count
  • groupBy

Example: Filtering by Related Models Using every

use Lib\Prisma\Classes\Prisma;

$prisma  = Prisma::getInstance();
$icons   = $prisma->icon->findMany([
    'where' => [
        'categories' => [
            'every' => [
                'name' => [
                    'equals' => $categoryName
                ]
            ]
        ]
    ],
    'include' => [
        'categories' => true
    ],
    'orderBy' => [
        'name' => 'asc'
    ]
]);

echo "<pre>";
echo "Icons found: " . print_r($icons, true);
echo "</pre>";

    

Explanation

This query returns all icon records where every related category (if any exist) has a name equal to $categoryName. Use the every operator for cases where all related items must match the specified condition.