我有一个实体A,有几个实体B。我几乎可以正确显示所有内容,但实体B指的是实体C(指实体D)。
我希望能够显示C和D的描述,但是,我无法理解我将如何实现这一目标。
所以,我的实体的一个简单版本:
A
B.description
B.idA
B.idC
C.description
C.idD
D.description
在我的控制器中,我有:
public function showAction(A $a)
{
$aForm = $this->createForm('AppBundle\Form\AType', $a);
$em = $this->getDoctrine()->getManager();
$b_all = $em->getRepository('AppBundle:B')->findBy( array('aId' => $a->getId()) );
return $this->render('a_detail.html.twig', array(
'a' => $a,
'b_all' => $b_all,
'b_count' => count($b_all),
'aform' => $a->createView(),
));
}
在我的Twig文件中,我可以使用内置的Twig函数显示A,并且所有B都很容易。
<div id='aForm'>
{{ form(aForm) }}
</div>
<ul class="tabs" data-tabs id="module-tabs">
{% set tabcount = 0 %}
{% for b in b_all %}
<li class="tabs-title {% if tabcount == 0 %}is-active{% endif %}">
<a href="#panel{{ tabcount }}">{{ b.description }}</a>
</li>
{% set tabcount = tabcount + 1 %}
{% endfor %}
</ul>
<div class="tabs-content" data-tabs-content="module-tabs" data-equalizer data-equalize-on="large">
{% set tabcount = 0 %}
{% for b in b_all %}
<div class="tabs-panel {% if tabcount == 0 %}is-active{% endif %}" id="panel{{ tabcount }}" data-equalizer-watch>
{{ b.description }}
{{ b.idC }} {{ c.description }}
{{ c.idD }} {{ d.description }}
</div>
{% set tabcount = tabcount + 1 %}
{% endfor %}
</div>
显然,我没有将C(或D)传递到我的Twig文件中,但是,我想显示描述而不是C的ID(以及D的描述)。
我的第一个想法是,在B的自定义存储库函数中使用leftJoin。但是我不确定如何在Symfony / Doctrine中解析相同的列名。