Search code examples
sqldoctrine-ormtypo3-flow

Get table name of an entity for a query in TYPO3 Flow


Does anybody know how to get the table name of an entity within a repository class? With Extbase this seems to be easily possible but I can't find no helper class within TYPO3 Flow. I need this for a raw SQL query within the repository of an entity.


Solution

  • RTFM: http://wiki.typo3.org/Flow_Cookbook#Execute_arbitrary_DQL. So with the DQL I'm able to use the class names directly in a query.

    /**
     * @Flow\Inject
     * @var \Doctrine\Common\Persistence\ObjectManager
     */
    protected $entityManager;
    
    [...]
    
    $dql = 'SELECT COUNT(e) FROM Vendor\Package\Domain\Model\Entity e WHERE e.property = :property';
    
    $query = $this->entityManager->createQuery($dql);
    $query->setParameters(array('property' => $property));
    $result = $query->execute();