Entity misbehaving whilst rendering PDF with twig, symfony2 and doctrine
<p>I'm facing a funny issue here, I will do my best to explain it:</p>
<p>I have an <strong>Order</strong> entity and an <strong>orderProducts</strong> with a one to many relation.</p>
<p>Now I'm trying to generate a PDF invoice.</p>
<p>So I built my invoice using twig, then I <a href="https://github.com/KnpLabs/snappy" rel="nofollow noreferrer">use Knp\Snappy\Pdf;</a> then it's just the following</p>
<pre><code>$snappy = new Pdf($myProjectDirectory . 'vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');
$renderedView = $this-&gt;renderView(
    'ERPBundle:Orders:invoicepdf.html.twig', array(
        'order' =&gt; $order,
        'invoice' =&gt; $invoice
    )
);
$snappy-&gt;generateFromHtml($renderedView, $invoicePath);
</code></pre>
<p>In the generated PDF, the orderProducts are duplicated, meaning I get the same row displayed twice.</p>
<p>I've rendered the template separately to view it in the browser and the orderProdcuts displays correctly, I used the same code to retrieve the data.</p>
<p>So I'm guessing this has got to be an issue between Snappy rendering of the html output + doctrine's lazy load. But I don't have the skills to debug this.</p>