Doctrine not allowing ResultSetMappingBuilder to work

前端 未结 2 374
[愿得一人]
[愿得一人] 2020-12-19 09:18

I\'m using Symfony 2 with doctrine. I\'ve set up a custom repository with a custom find function. As it joins to a subquery I\'m pretty sure from what I\'ve read that I\'ll

相关标签:
2条回答
  • 2020-12-19 09:32

    When creating ResultSetMappingBuilder specify COLUMN_RENAMING_INCREMENTrename mode for Doctrine to automatically resolve conflicts

    Then in the actual query you need to use select generator:

        $rsm = new ResultSetMappingBuilder(
            $entityManager, 
            ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT
        );
    
        $rsm->addRootEntityFromClassMetadata("Product", "p");
        $rsm->addJoinedEntityFromClassMetadata("ProductImage", "pi", "p", "images");
    
        $query = $entityManager->createNativeQuery("
            SELECT " . $rsm->generateSelectClause() . " 
            FROM product p 
            JOIN product_image pi
        ", $rsm);
    
    0 讨论(0)
  • 2020-12-19 09:34

    Just closing the question as it's solved:

    For anyone who has the same problem the problem was with the 4th parameter sent on this line:

    $rsm->addJoinedEntityFromClassMetadata('Wfuk\DuckBundle\Entity\Ducks', 'ducks', 'c', 'ducks');
    

    Which should have held the field within the Country class that I was using to store the arrayCollection of ducks within it.

    0 讨论(0)
提交回复
热议问题