public function findActiveEvents($start, $end)
{
$expr = Criteria::expr();
$criteria = Criteria::create();
$criteria->where(
$expr->andX($expr->gte('start', $start), $expr->lte('end', $end)
));
return $this->matching($criteria);
}
So let's say my event entity has a category and category has many events, how would I filter these?
If you want to get collection of inactive events on category object you could use criteria class
class Category{
protected $events; // (oneToMany)
// ...
protected getEvents() { // default method
return $this->events;
}
protected getActiveEvents() {
$expr = Criteria::expr();
$criteria = Criteria::create();
$criteria->where(
$expr->andX($expr->gte('start', $start), $expr->lte('end', $end)
));
return $this->events->matching($criteria);
}
}
How filter data inside entity object in Symfony 2 and Doctrine