title: Symfony2 Doctrine Get reference based on attribute
body: <p>in my Symfony2/Doctrine2 project I have an entity <code>Person</code> which has a birth date. I have another entity <code>Agegroup</code> which stores a name and some more information for a group based on the age in years.</p>
  
  <p>Example:<br>
  <code>Person</code> Name: xy Date: 1980-05-06<br>
  <code>Agegroup</code>: From: 1  To: 10<br>
  <code>Agegroup</code>: From: 11  To: 20<br>
  <code>Agegroup</code>: From: 21  To: 30  </p>
  
  <p>I want to get the Agegroup which a person currently belongs to, from within the entity (based on current date). </p>
  
  <p>i.e. :$person->getCurrentAgeGroup()</p>
  
  <p>Therefore I would have to access another repository class from within the entity, which is obviously not a good thing to do.</p>
  
  <p>Is there a way to implement this kind of functionality?</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/7673270/service-objects-with-doctrine2-and-symfony2">Using EntityManager inside Doctrine 2.0 entities</a>
  which could be a solution to the problem. Unfortunately I didn't find a solution to implementent this. Do I have to inject the service somehow into the entity?</p>
  
  <p>Maybe there are other best practices for this kind of problem?</p>