title: Best way to filter a relationship from a twig template
body: <p>in my Symfony2 project, I've two entities: Spot and Weather, with a one-to-many relationship "weatherReports" between the two entities.</p>
  
  <p>Some weather reports are outdated, so I would like do create an "activeWeatherRecords" method to filter the Weather entities in a Spot entity.</p>
  
  <p>Unfortunately, I can't see how to do this. The idea is not to fetch objects from the controller since the Spot objects are favorited, linked to an User object and accessed directly from a twig template.</p>
  
  <p>So here is the question: What's the best way to filter a relationship directly from a twig template?</p>
  
  <p><strong>UPDATE 09/11/2013</strong></p>
  
  <p>I managed to filter my relationship with a filtering method on my relationship.</p>
  
  <p>In my spot entity, I declared a getActiveWeatherRecords() method:</p>
  
  <pre><code>public function getActiveWeatherReports()
      {
          // Date
          $date = new \DateTime(date('Y-m-d 12:00:00', time()));
  
          // Criteria
          $criteria = Criteria::create()
              -&gt;where(Criteria::expr()-&gt;gte("date", $date))
              -&gt;orderBy(array("date" =&gt; Criteria::ASC))
          ;
  
          return $this-&gt;weatherReports-&gt;matching($criteria);
      }
  </code></pre>
  
  <p>And I can call this method from a twig template as simply as follow:</p>
  
  <pre><code>[...]
  {% for weatherReport in spot.activeWeatherReports %}
  [...]
  {% endfor %}
  [...]
  </code></pre>