title: Query Builder inside entity - Doctrine
body: <p>I'm looking to a better way to write this function.
  It's inside a Doctrine Entity Model</p>
  
  <pre><code>public function getCompanySubscriptions()
  {
      foreach ($this-&gt;subscriptions as $key =&gt; $value) {
          if ($value-&gt;getPlan()-&gt;getType() == 'E' &amp;&amp; $value-&gt;getActive()) {
              return $value;
          }
      }
      return null;
  }
  </code></pre>
  
  <p><code>$this-&gt;subscriptions</code> is a many-to-one collection and can have different "types" (but only one of them with type "E").</p>
  
  <p>Problem is: If the <code>Company</code> has too many <code>$subscriptions</code> this function will be too slow to return that only one of type "E" which I need to check when  building the view with TWIG. The solution would be to use a <code>QueryBuilder</code>, but I haven't found a way to use it directly from the entity model.</p>