Q:

Best way to filter a relationship from a twig template

in my Symfony2 project, I've two entities: Spot and Weather, with a one-to-many relationship "weatherReports" between the two entities.
Some weather reports are outdated, so I would like do create an "activeWeatherRecords" method to filter the Weather entities in a Spot entity.
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.
So here is the question: What's the best way to filter a relationship directly from a twig template?
UPDATE 09/11/2013
I managed to filter my relationship with a filtering method on my relationship.
In my spot entity, I declared a getActiveWeatherRecords() method:
public function getActiveWeatherReports()
    {
        // Date
        $date = new \DateTime(date('Y-m-d 12:00:00', time()));

        // Criteria
        $criteria = Criteria::create()
            ->where(Criteria::expr()->gte("date", $date))
            ->orderBy(array("date" => Criteria::ASC))
        ;

        return $this->weatherReports->matching($criteria);
    }

And I can call this method from a twig template as simply as follow:
[...]
{% for weatherReport in spot.activeWeatherReports %}
[...]
{% endfor %}
[...]

A:

One way is to create a finder method that fetches only active records. You could put that method in a Doctrine repository, call it from your controller (or the Service Layer) and pass it to your template.
Another way is to add a filtering method right to your entity. This way you don't have to call a separate method and pass the result to a template — the entity you pass to the entity will be enough.

