title: Stop Doctrine / Symfony from loading associated entities during foreach? (lazy loading not happening)
body: <p>I'm seeing doctrine generating additional queries to load entities that I'm not directly accessing.  I thought that lazy loading meant these associate entities wouldn't get loaded.  Can you help me figure out why the queries are happening and how to stop them?</p>
  
  <p>Here's the entities in question:</p>
  
  <pre><code>class Invoice
  {
      /**
      * @ORM\OneToMany(targetEntity="InvoiceCard", mappedBy="invoice")
      */
      protected $cards;
  
      ...
  }
  class BaseInvoiceCard
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var integer
       *
       * @ORM\ManyToOne(targetEntity="Invoice", inversedBy="cards")
       * @ORM\JoinColumn(name="invoice_id", referencedColumnName="id")
       */
      protected $invoice;
  
      /**
       * @var integer
       *
       * @ORM\ManyToOne(targetEntity="Printing")
       * @ORM\JoinColumn(name="printing_id", referencedColumnName="id")
       */
      protected $printing;
  
      ...
  }
  class InvoiceCard extends BaseInvoiceCard{ ... }
  class Printing{ ... }
  </code></pre>
  
  <p>This line of code doesn't cause any queries to the InvoiceCards table:</p>
  
  <pre><code>$cards = $invoice-&gt;getCards();
  </code></pre>
  
  <p>Once I do this:</p>
  
  <pre><code>foreach($cards as $card){
      //do nothing in this loop
  }
  </code></pre>
  
  <p>I get a "SELECT ... FROM invoicecard", which is expected.  </p>
  
  <p><em>However</em>, I'm also getting a "SELECT ... FROM printing" for every $card in $cards.  I never call $card->getPrinting().  This happens even if I do nothing at all inside the loop; just running it causes doctrine to run these queries.</p>
  
  <p>Why this happening and how can I prevent it?</p>
  
  <p><strong>EDIT:</strong>  This is the code for getCards().</p>
  
  <pre><code>/**
   * Get cards
   *
   * @return \Doctrine\Common\Collections\Collection 
   */
  public function getCards()
  {
      return $this-&gt;cards;
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong>
  I've found a workaround to this problem, though it's not going to solve things in the long run.  I fetch the InvoiceCards as an array, rather than having doctrine hydrate them as entities.</p>
  
  <pre><code>$query-&gt;getArrayResult();
  </code></pre>
  
  <p>In my current situation, this technique is better anyways, since I don't require the overhead of full hydration.</p>
  
  <p>However, the application will be working with InvoiceCards in many places, and the original issue will be still be a problem then.  I feel like either I've misunderstood Doctrine's lazy loading, or it isn't working as expected.</p>