0

I try to get all users who has a mail in three different properties with in expression

$qb = $this->createQueryBuilder('i');
$qb->where(':email in (i.firstMail,i.secondtMail,i.thirdtMail)');

   

I got this error in getResult

[Syntax Error] line 0, col 61: Error: Expected Doctrine\\ORM\\Query\\Lexer::T_OPEN_PARENTHESIS, got 'i'
user3427807
  • 31
  • 1
  • 3

2 Answers2

0

In DQL the lexer expects the contents of the IN() function to either be a subselect or a comma separated list of literals. https://github.com/doctrine/orm/blob/f92c3dba324923729373b1fdfc324b77e5cc5900/lib/Doctrine/ORM/Query/Parser.php#L3102

To get what you want you must either create multiple where conditions or aggregate the other 3 fields in a subselect.

Additionally, I recommend using the expression builder for complex expressions: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/query-builder.html#the-expr-class

scriptibus
  • 91
  • 2
0

You can try:

$qb = $this->createQueryBuilder('i');
$qb->andWhere('i.firstMail LIKE :email OR i.secondtMail LIKE :email OR i.thirdtMail LIKE :email')
   ->setParameter('email', '%'. $email. '%');
poppies
  • 142
  • 6