I am trying to build a query with DQL that is split up in several functions, so I can re-use these functions again and again for different queries.
So far this worked great, until I needed to re-use an alias from a join
Let's say I have these two functions:
public function addEquipmentSubType(QueryBuilder $builder): QueryBuilder
{
return $builder
->andWhere(est.code = :code)
->leftJoin('q.equipmentSubType', 'est')
->addSelect('est')
->setParameter('code', '123');
}
and then this one:
public function search(QueryBuilder $builder): QueryBuilder
{
return $builder
->andWhere('q.projectNumber LIKE :search OR est.name LIKE :search')
}
This triggers an error, saying 'est' is not defined. It seems like the only way to fix this, is to join equipmentSubtype again, but this causes the eventual query to have 2 joins with the same table.
Is there a way to pass those table aliasses from function to function so I can reuse the join?