NOTE: This is Native Query specific
I have 2 related entites \"CrmBusinessPartner\" and \"RefCountry<
Well, well, well...it looks like you have to add rc.id AS ref_country_id,
in query and $rsm->addFieldResult('rc','ref_country_id','id');
like this:
$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
$rsm->addEntityResult('Entity\CrmBusinessPartner', 'bp');
$rsm->addFieldResult('bp','id','id');
$rsm->addFieldResult('bp','vat','vat');
$rsm->addFieldResult('bp','business_partner_name','name');
$rsm->addJoinedEntityResult('Entity\RefCountry', 'rc', 'bp', 'billingCountry');
$rsm->addFieldResult('rc','ref_country_id','id');
$rsm->addFieldResult('rc','ref_country_name','name');
$em = $this->getEntityManager()
->createNativeQuery('
SELECT
bp.id,
bp.vat,
bp.name AS business_partner_name,
rc.id AS ref_country_id,
rc.name AS ref_country_name
FROM crm_business_partner bp
LEFT JOIN ref_country rc ON bp.ref_country_id=rc.id
',
$rsm
);
return $em->getResult();
It is working as expected like this.
I wish somebody told me this before (Doctrine documentation...watching you) :D