Is there a way to write DQL queries without specifying the fully qualified name of the class?
Is there a way to create the following query:
return $this->getEntityManager()->createQuery(
'SELECT i
FROM Company\AccountingBundle\Entity\Invoice i
WHERE i.id = :id'
)->setParameter('id', 1)
->getResult();
Like this :
use Company\AccountingBundle\Entity\Invoice;
....
return $this->getEntityManager()->createQuery(
'SELECT i
FROM Invoice i
WHERE i.id = :id'
)->setParameter('id', 1)
->getResult();
Or something similar. I really would avoid to set the full FQN in the DQL.
But I didn't find any "setClass" or another method to do this.
EDIT FOR CONTEXT
In fact, it is a Symfony project and the query is inside in a Repository class. I have a Doctrine XML definition of the entity, an entity and the entity repository also defined in the XML, but I always need to explicitly define the FQN, Any ideas?
$work_class="Company\AccountingBundle\Entity\Invoice"; return $this->getEntityManager()->createQuery( 'SELECT i FROM ' . $work_class . ' i WHERE i.id = :id' )->setParameter('id', 1) ->getResult();
– Adam P.sprintf
and just passInvoice::class
for the placeholder value. – El_Vanja