My problem
I am performing a join using doctrine2
query builder and symfony3
.
My controller contains following code:
$rp_konta = $this->getDoctrine()->getRepository('AppBundle:konto');
$query = $rp_konta->createQueryBuilder('p')
->select('p')
->addSelect('SUM(g.kwota)')
->leftJoin('p.ksiegowaniaWinien', 'g')
->getQuery();
which results in the SQL query:
SELECT k0_.id AS id_0, k0_.kod_konta AS kod_konta_1, k0_.nazwa_konta AS nazwa_konta_2, k0_.typ_konta AS typ_konta_3, k0_.aktywne AS aktywne_4, SUM(d1_.kwota) AS sclr_5 FROM konto k0_ LEFT JOIN dziennik d1_ ON k0_.id = d1_.konto_winien_id AND (d1_.usuniety IS NULL) WHERE k0_.id IN ('1', '2', '3');
Please note that each column name is followed by a suffix id_0 , kod_konta_1 and so on.
As my twig template looks like the following:
{% for konto in konta_pagination %}
<tr>
<td>{{ konto.id }}</td>
{% endfor %}
and the id column returned as a result of SQL query is marked by doctrine as id_0
and not as id
I get the following error:
Key "id" for array with keys "0, 1" does not exist in AppBundle::/raport/saldaKont.html.twig at line 18
How should I modify the query so that it returns the array with keys consistent without any suffix?
Update 1: Entities code
Based on @Tiriel request please find below also my entities code.
Dziennik entity:
class dziennik
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/.../
/**
* @ORM\ManyToOne(targetEntity="konto", inversedBy="ksiegowaniaWinien")
* @Gedmo\Versioned
*/
protected $kontoWinien;
/**
* @ORM\ManyToOne(targetEntity="konto", inversedBy="ksiegowaniaMa")
* @Gedmo\Versioned
*/
protected $kontoMa;
}
Konto entity:
class konto
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/.../
/**
* @ORM\OneToMany(targetEntity="dziennik", mappedBy="kontoWinien")
*/
protected $ksiegowaniaWinien;
/**
* @ORM\OneToMany(targetEntity="dziennik", mappedBy="kontoMa")
*/
protected $ksiegowaniaMa;
}