Assume I have Product entities and Review entities attached to products. Is it possible to attach a fields to a Product entity based o
If you're on Doctrine 2.1+, consider using EXTRA_LAZY associations:
They allow you to implement a method like yours in your entity, doing a straight count on the association instead of retrieving all the entities in it:
/**
* @ORM\OneToMany(targetEntity="Review", mappedBy="Product" fetch="EXTRA_LAZY")
*/
private $Reviews;
public function getReviewsCount() {
return $this->Reviews->count();
}