2 つのクラス (プロトコルと履歴) の間に双方向の 1 対多の関係があります。特定のプロトコルを検索すると、そのプロトコルに関連付けられたすべての履歴エントリが表示されるはずです。
テンプレートのレンダリング中に、次を渡します。
return $this->render('FunarbeProtocoloAdminBundle:Protocolo:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
'history' => $entity->getHistory(),
)
);
entity->getHistory()
配列の代わりに PersistentCollection を返すため、次の場合にエラーが発生します。
{% for hist in history %}
<tr>
<td>{{ hist.dtOcorrencia|date('d/m/Y H:i') }}</td>
<td>{{ hist.dtRetorno|date('d/m/Y H:i') }}</td>
</tr>
{% endfor %}
I を渡す代わりに$entity->getHistory()
を渡す$em->getRepository('MyBundle:History')->findByProtocol($entity)
と、正常に動作します。しかし、双方向の関係を持つ主なポイントは、リポジトリを開いたり、新しい結果セットを明示的に開いたりすることを避けることだと思います。
私は何か間違ったことをしていますか?どうすればいいですか?