{"record":{"id":"9e2a64a02fbc4456","repo":"doctrine/orm","slug":"s-the-alias-for-entity-s-must-not-be-omitted","errorCode":null,"errorMessage":"%s(): The alias for entity %s must not be omitted.","messagePattern":"(.+?)\\(\\): The alias for entity (.+?) must not be omitted\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/QueryBuilder.php","lineNumber":781,"sourceCode":"     *         ->where('u.id = :user_id')\n     *         ->setParameter('user_id', 1);\n     * </code>\n     *\n     * @param class-string|null $delete The class/type whose instances are subject to the deletion.\n     * @param string|null       $alias  The class/type alias used in the constructed query.\n     *\n     * @return $this\n     */\n    public function delete(string|null $delete = null, string|null $alias = null): static\n    {\n        $this->type = QueryType::Delete;\n\n        if (! $delete) {\n            return $this;\n        }\n\n        if (! $alias) {\n            throw new InvalidArgumentException(sprintf(\n                '%s(): The alias for entity %s must not be omitted.',\n                __METHOD__,\n                $delete,\n            ));\n        }\n\n        return $this->add('from', new Expr\\From($delete, $alias));\n    }\n\n    /**\n     * Turns the query being built into a bulk update query that ranges over\n     * a certain entity type.\n     *\n     * <code>\n     *     $qb = $em->createQueryBuilder()\n     *         ->update('User', 'u')\n     *         ->set('u.password', '?1')\n     *         ->where('u.id = ?2');","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/QueryBuilder.php#L763-L799","documentation":"delete($delete, $alias) switches the builder to a bulk DELETE and, when an entity name is given, registers it as a FROM expression, which in DQL always needs an alias. The builder cannot invent one for you, so omitting the second argument throws InvalidArgumentException immediately. Calling delete() with no arguments is legal and only sets the statement type.","triggerScenarios":"$qb->delete(User::class) with the alias omitted; $qb->delete(User::class, null) explicitly; translating a DQL string like 'DELETE FROM User u' into builder calls and dropping the alias.","commonSituations":"Refactoring raw DQL to QueryBuilder; code generators that skip optional-looking parameters; copy-paste from select()-style examples.","solutions":["Pass the alias: $qb->delete(User::class, 'u').","Or split the calls: $qb->delete()->from(User::class, 'u')."],"exampleFix":"// before\n$qb = $em->createQueryBuilder()->delete(User::class); // InvalidArgumentException\n\n// after\n$qb = $em->createQueryBuilder()->delete(User::class, 'u');","handlingStrategy":"validation","validationCode":"// wrapper that makes the alias mandatory-by-default at your call sites\npublic function bulkDelete(string $entity, string $alias = 'e'): QueryBuilder\n{\n    return $this->em->createQueryBuilder()->delete($entity, $alias);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember both arguments are required once the entity is passed: delete(Entity::class, 'u').","Standardize a default alias in wrapper methods so call sites cannot omit it.","Cover builder usage in unit tests; the exception is thrown at build time and fails fast."],"tags":["doctrine-orm","query-builder","delete","bulk-operations"],"backgroundTag":"missing-required-argument","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}