Skip to content

[RFC] Expose EntityRepository::expr()#12525

Open
VincentLanglet wants to merge 2 commits into
doctrine:3.7.xfrom
VincentLanglet:expr
Open

[RFC] Expose EntityRepository::expr()#12525
VincentLanglet wants to merge 2 commits into
doctrine:3.7.xfrom
VincentLanglet:expr

Conversation

@VincentLanglet

Copy link
Copy Markdown
Contributor

Previously

$qb = $this->createQueryBuilder();
$qb
      ->select('u')
      ->from('User', 'u')
      ->where($qb->expr()->eq('u.id', 1));

Now

$this
     ->createQueryBuilder()
      ->select('u')
      ->from('User', 'u')
      ->where($this->expr()->eq('u.id', 1));

I know we could write

$this
     ->createQueryBuilder()
      ->select('u')
      ->from('User', 'u')
      ->where($this->getEntityManager()->getExpressionBuilder()->eq('u.id', 1));

but that's a little more complicated and people are used to the expr syntax (they might not even not it's called an ExpressionBuilder).

@VincentLanglet VincentLanglet changed the title [RFC] Expose EntityRepository::expr(- [RFC] Expose EntityRepository::expr() Jul 2, 2026

@greg0ire greg0ire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Are there docs or tests that could be simplified?

Comment thread src/EntityRepository.php Outdated
return $this->em;
}

protected function expr(): Expr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function expr(): Expr
final protected function expr(): Expr

@VincentLanglet

Copy link
Copy Markdown
Contributor Author

Sounds good to me. Are there docs or tests that could be simplified?

I checked and no:

  • docs are about queryBuilder->expr, none of this code is in the EntityRepository context
  • tests are testing querybuilder without being in an EntityRepository context too

@VincentLanglet

Copy link
Copy Markdown
Contributor Author

I saw "Missing test" was added ; but not sure what should be written for such a basic method added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants