How can I call method of entity in a repository querybuilder
<p>I have this scenario:
a entity Person, a repository for Person and a select form type.</p>

<p>I should take in my select form only active person.</p>

<p>In the entity there is a public method "isActive" that check if a Person have the permission to access in my private area. This method return true or false and is not a column in the db table, it is calculated.</p>

<p>I need to access this flag from my querybuilder in the Person repository.
Is it possible?
below the code of my querybuilder in the repository.</p>

<pre><code>public function getQueryBuilderForEventRegistration()
{
    $queryBuilder = $this-&gt;createQueryBuilder('e')-&gt;orderBy('e.surname', 'asc')-&gt;addOrderBy('e.name', 'asc');

    return $queryBuilder;
}
</code></pre>

<p>and the public method in the entity Person tha t i have to access:</p>

<pre><code>public function getIsActive()
{
    if (empty($this-&gt;getUser()))
    {
        return false;
    }

    if (!$this-&gt;getUser()-&gt;isEnabled())
    {
        return false;
    }

    /* @var $service \Siderweb\SubscriptionBundle\Entity\UserService */
    foreach ($this-&gt;getUser()-&gt;getServices() as $service)
    {
        if (!$service-&gt;getIsExpired())
        {
            return true;
        }
    }

    return false;
}
</code></pre>

<p>and my type:</p>

<pre><code>$builder-&gt;add('personExist', 'entity', array(
            'class' =&gt; 'MyAppUserBundle:Person',
            'property' =&gt; 'name',
            'required' =&gt; false,
            'multiple' =&gt; false,
            'mapped' =&gt; false,
            'empty_value' =&gt; '-- New person --',
            'query_builder' =&gt; function(PersonRepository $repo) use ($options) {
                return $repo-&gt;getQueryBuilderForEventRegistration();
            }
        ))
</code></pre>

<p>as suggested I edit my repository like this:</p>

<pre><code> public function getQueryBuilderForEventRegistration(Company $company = null, Event $event = null, $emailFilter = null)
{
    $queryBuilder = $this-&gt;createQueryBuilder('e')-&gt;orderBy('e.surname', 'asc')-&gt;addOrderBy('e.name', 'asc');

    $people = $queryBuilder-&gt;getQuery()-&gt;execute();
    $peopleToShow = array();

    foreach ($people as $person)
    {
        if ($person-&gt;getIsActive())
        {
            array_push($peopleToShow, $person);
        }
    }

    return $peopleToShow;
}
</code></pre>

<p>but now I don't know how to put this array in my typeForm. Any idea?</p>