<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="-&gt;add('recipientContacts', EntityType::class, [
    'mapped' =&gt; false,
    'required' =&gt; false,
    'multiple' =&gt; true,
    'expanded' =&gt; false,
    'class' =&gt; Contact::class,
    'query_builder' =&gt; function (EntityRepository $repository) {
        return $repository-&gt;createQueryBuilder('contact')
            -&gt;where('contact.enabled = true')
            -&gt;orderBy('contact.name', 'ASC');
    },
    'group_by' =&gt; 'groups.name',
])"><pre class="notranslate">-&gt;add(<span class="pl-s">'recipientContacts'</span>, <span class="pl-v">EntityType</span>::class, [
    <span class="pl-s">'mapped'</span> =&gt; <span class="pl-c1">false</span>,
    <span class="pl-s">'required'</span> =&gt; <span class="pl-c1">false</span>,
    <span class="pl-s">'multiple'</span> =&gt; <span class="pl-c1">true</span>,
    <span class="pl-s">'expanded'</span> =&gt; <span class="pl-c1">false</span>,
    <span class="pl-s">'class'</span> =&gt; <span class="pl-v">Contact</span>::class,
    <span class="pl-s">'query_builder'</span> =&gt; <span class="pl-k">function</span> (<span class="pl-smi"><span class="pl-smi">EntityRepository</span></span> <span class="pl-s1"><span class="pl-c1">$</span>repository</span>) {
        <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span>repository</span>-&gt;<span class="pl-en">createQueryBuilder</span>(<span class="pl-s">'contact'</span>)
            -&gt;<span class="pl-en">where</span>(<span class="pl-s">'contact.enabled = true'</span>)
            -&gt;<span class="pl-en">orderBy</span>(<span class="pl-s">'contact.name'</span>, <span class="pl-s">'ASC'</span>);
    },
    <span class="pl-s">'group_by'</span> =&gt; <span class="pl-s">'groups.name'</span>,
])</pre></div>
<p dir="auto">Important is this line:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" 'group_by' =&gt; 'groups.name',"><pre class="notranslate"> <span class="pl-s">'group_by'</span> =&gt; <span class="pl-s">'groups.name'</span>,</pre></div>
<p dir="auto">This is not working because there is a Many-to-Many relation between <code class="notranslate">Contact</code> and <code class="notranslate">ContactGroup</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Neither the property &quot;name&quot; nor one of the methods &quot;getName()&quot;, &quot;name()&quot;, &quot;isName()&quot;, &quot;hasName()&quot;, &quot;__get()&quot; exist and have public access in class &quot;Doctrine\ORM\PersistentCollection&quot;."><pre class="notranslate"><code class="notranslate">Neither the property "name" nor one of the methods "getName()", "name()", "isName()", "hasName()", "__get()" exist and have public access in class "Doctrine\ORM\PersistentCollection".
</code></pre></div>
<p dir="auto">(Yes: <code class="notranslate">ContactGroup</code> contains <code class="notranslate">getName()</code>)</p>
<p dir="auto">In <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="43646560" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/12006" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/12006/hovercard" href="https://github.com/symfony/symfony/pull/12006">#12006</a>, Symfony introduced the concept of ExpressionFunctionProviders. The consequence is that you cannot use the DependencyInjection component from 2.6 together with an older version of the ExpressionLanguage component. Is there a way to make the developer's experience easier? Can we maybe add the old behaviour as a fallback?</p>