1

All is in the title.

    $qb->expr()->like('a.lieu', ':advertLieu');
->setParameter('advertLieu', $postedAdvert->getVille()->getName()."%")

This will check if in the a.lieu entry there is a substring starting with the advertLieu parameter.

I want the inverse , like this :

$qb->expr()->like(':advertLieu', '%a.lieu%',);
    ->setParameter('advertLieu', $postedAdvert->getVille()->getName())

So, check if ma database entry a.lieu is contained in the parameter advertLieu

I found this : MySQL: What is a reverse version of LIKE? but How can i implement this in my query builder ?

Update

I have a similar question : If i have a collection of entity in my database and want to check if my parameter exist in this array like : $qb->expr()->in('u.ids', $id)

I mean check if u.ids contain $id. Is it possible ? Thanks

Community
  • 1
  • 1
LedZelkin
  • 586
  • 1
  • 10
  • 24

1 Answers1

1

Try this:

$qb->expr()
    ->like(
        ':advertLieu', 
        $qb->expr()
            ->concat(
                $qb->expr()->literal('%'), 
                $qb->expr()->concat('a.lieu', $qb->expr()->literal('%'))
            )
     );
->setParameter('advertLieu', $postedAdvert->getVille()->getName())

For your update I would suggest you do this:

$qb->expr()->in('u.id', ':ids');
->setParameter('ids', $id)
Max Scott
  • 81
  • 5
  • Thank you a lot . Maybe can you answer to my update. I have a similar case but i don't know how to implement it – LedZelkin Aug 29 '15 at 22:32
  • Thanks for reply , for the second question, i want the inverse use. Check if the array collection ( who is in database) contain the parameter $id. In you case, it look like i'll pass the array in parameter and not the unique id. – LedZelkin Aug 30 '15 at 09:22
  • NVM, i found the solution , we can use like on serialized object [check here](http://stackoverflow.com/questions/19709699/symfony2-doctrine2-display-items-by-category-with-query) – LedZelkin Aug 30 '15 at 09:58
  • Sorry about the misunderstanding. Glad you found the solution. – Max Scott Aug 30 '15 at 18:00