This is similar to this question posted previously:
In Symfony2, should I use an Entity or a custom Repository
Lets say I have a car entity and a Wheels entity. A car has many wheels but a wheel has a single car.
In my controller I already have access to the car. I’m using the relation to get the wheels belonging to the car.
$car = $this->getCar();
$wheels= $car->getWheels();
The above works and gives me access to the wheels belonging to the current car. But instead of getting all wheels, I only need wheels where flat = 0.
Is there a better way than a repository to get the wheels belonging to the car entity where flat = 0?
I was thinking of creating a getter in the car entity (getNonFlatWheels) then filtering the wheels so that only the non flat wheels are returned.
Seems there would be a more standard solution.
I do not know your entities structure, but in a similar situation I use this snippet of code. You can try to put it in CarRepository class.
I hope it will help you.