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
When creating ResultSetMappingBuilder
specify COLUMN_RENAMING_INCREMENT
rename 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);
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.