-1

I am trying to match two entities based on a set of criteria but I can't seem to make it work in this particular case.

For the purpose of the example, let's say I have:

Article with N tags Category with 1 tag

What I would like to do would be to, in my repository do something like:

$this->createQueryBuilder('article')
  ->join('App\Enttiy\Category', 'c', Join::WITH, 'c.id = :category_id)
  ->where('c.tag IN article.tags')
  ->andWhere(':category_id', $category->getId())
  ->getQuery()
  ->getResult();

Of course, in this example, the simplest way would be to define a relationship between my objects but in my real case, this relationship would be a nightmare .

The problem I face is the where line as the IN clause doesn't work that way.

Anyone has an idea of how I could use DQL to do this ? :)

Thanks by advance

Zahori
  • 446
  • 1
  • 4
  • 16
TPouliquen
  • 114
  • 2
  • 14

1 Answers1

0

First of all your andWhere will not work, you need to use ->setParameter() instead, like this:

$this->createQueryBuilder('article')
  ->join('App\Enttiy\Category', 'c', Join::WITH, 'c.id = :category_id')
  ->where('c.tag IN article.tags')
  ->setParameter('category_id', $category->getId())
  ->getQuery()
  ->getResult();

After, you forgot an ' in your join, here: 'c.id = :category_id, I added it in my example (don't know if it's a typing error).

Please try with this and tell me if you have an error again and if you have an error, please tell me what is it.

Zahori
  • 446
  • 1
  • 4
  • 16