After reading several other questions, it looks like it's not advisable to have an entity class use a Repository. So given these repositories:
class RestaurantRepository {
public function findAll() { ... }
}
class ReviewRepository {
public function findByRestaurant(Restaurant $restaurant) { ... }
}
I should not do this in my class:
class Restaurant {
public function getReviews() {
// ...
return $restaurantRepository->findByRestaurant($this);
}
}
Buts let's say I have this controller, which gives a list of Restaurants to the view:
class IndexController {
public function indexAction() {
$restaurants = $restaurantRepository->findAll();
$this->view->restaurants = $restaurants;
}
}
What is the "good practice" to get each restaurant's reviews in the view script? I can therefore not do this:
foreach ($this->restaurants as $restaurant) {
$reviews = $restaurant->getReviews();
}
And I guess that injecting the ReviewRepository in the view is not what we can call a "best practice" as well...
Any comment welcome!