<p dir="auto">When a parent give a constraint to his childrens by annotations,<br>
whe cannot remove the constraint by annotation in the class child</p>
<p dir="auto">It's possible to had a way to manage inheritance strategy like this ? :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/** 
 * @assert:NotBlank()
 * @assert:NotInheritance()
 */"><pre class="notranslate"><code class="notranslate">/** 
 * @assert:NotBlank()
 * @assert:NotInheritance()
 */
</code></pre></div>
<p dir="auto">or/and do this :<br>
$childObject-&gt;getValidator()-&gt;removeConstraint('name');</p>
<h1 dir="auto">Use case</h1>
<h2 dir="auto">Models:</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="abstract class AbstractUser
{
    private $username;
    private $password;
}

class ConcreteUser extends AbstractUser
{
    /**
     * @var UserProfile
     */
    private $profile;
}

class UserProfile
{
    private $name;
}"><pre class="notranslate"><code class="notranslate">abstract class AbstractUser
{
    private $username;
    private $password;
}

class ConcreteUser extends AbstractUser
{
    /**
     * @var UserProfile
     */
    private $profile;
}

class UserProfile
{
    private $name;
}
</code></pre></div>
<h2 dir="auto">validation.xml (1)</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;class name=&quot;AbstractUser&quot;&gt;
    &lt;property name=&quot;username&quot;&gt;
        &lt;constraint name=&quot;NotBlank&quot;&gt;
            &lt;option name=&quot;groups&quot;&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
    &lt;property name=&quot;password&quot;&gt;
        &lt;constraint name=&quot;NotBlank&quot;&gt;
            &lt;option name=&quot;groups&quot;&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
&lt;/class&gt;"><pre class="notranslate"><code class="notranslate">&lt;class name="AbstractUser"&gt;
    &lt;property name="username"&gt;
        &lt;constraint name="NotBlank"&gt;
            &lt;option name="groups"&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
    &lt;property name="password"&gt;
        &lt;constraint name="NotBlank"&gt;
            &lt;option name="groups"&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
&lt;/class&gt;
</code></pre></div>
<h2 dir="auto">validation.xml (2) :</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;class name=&quot;ConcreteUser&quot;&gt;
    &lt;property name=&quot;profile&quot;&gt;
        &lt;constraint name=&quot;Valid&quot; /&gt;
    &lt;/property&gt;
&lt;/class&gt;

&lt;class name=&quot;UserProfile&quot;&gt;
    &lt;property name=&quot;name&quot;&gt;
        &lt;constraint name=&quot;NotBlank&quot;&gt;                
            &lt;option name=&quot;groups&quot;&gt;
                &lt;value&gt;Profile&lt;/value&gt;
                &lt;value&gt;Registration&lt;/value&gt;
            &lt;/option&gt;
        &lt;/constraint&gt;            
    &lt;/property&gt;
&lt;/class&gt;"><pre class="notranslate"><code class="notranslate">&lt;class name="ConcreteUser"&gt;
    &lt;property name="profile"&gt;
        &lt;constraint name="Valid" /&gt;
    &lt;/property&gt;
&lt;/class&gt;

&lt;class name="UserProfile"&gt;
    &lt;property name="name"&gt;
        &lt;constraint name="NotBlank"&gt;                
            &lt;option name="groups"&gt;
                &lt;value&gt;Profile&lt;/value&gt;
                &lt;value&gt;Registration&lt;/value&gt;
            &lt;/option&gt;
        &lt;/constraint&gt;            
    &lt;/property&gt;
&lt;/class&gt;
</code></pre></div>
<p dir="auto">When setting <em>validation_groups</em> to <code class="notranslate">Registration</code>, the error messages show twice for the <code class="notranslate">UserProfile::name</code> property.</p>
<p dir="auto">A simple test can be adding the username validation again into <code class="notranslate">ConcreteUser</code> class constraints :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;class name=&quot;ConcreteUser&quot;&gt;
    &lt;property name=&quot;profile&quot;&gt;
        &lt;constraint name=&quot;Valid&quot; /&gt;
    &lt;/property&gt;
    &lt;property name=&quot;username&quot;&gt;
        &lt;constraint name=&quot;NotBlank&quot;&gt;
            &lt;option name=&quot;groups&quot;&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
&lt;/class&gt;"><pre class="notranslate"><code class="notranslate">&lt;class name="ConcreteUser"&gt;
    &lt;property name="profile"&gt;
        &lt;constraint name="Valid" /&gt;
    &lt;/property&gt;
    &lt;property name="username"&gt;
        &lt;constraint name="NotBlank"&gt;
            &lt;option name="groups"&gt;Registration&lt;/option&gt;
        &lt;/constraint&gt;
    &lt;/property&gt;
&lt;/class&gt;
</code></pre></div>
<p dir="auto">Then validation error messages will show twice on the <em>username</em> as well.</p>
<p dir="auto">In production environnement that's inconvenient :/</p>
<h1 dir="auto">Hack, ugly but....</h1>
<p dir="auto">For now, there is a hack until this is fixed, in form theme blocks (twig) :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{% block field_errors %}
{% spaceless %}
    {% if errors|length &gt; 0 %}
        &lt;ul&gt;
            {% set lastError = null %}
            {% for error in errors %}
                {% if lastError != error %}
                    &lt;li&gt;{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}&lt;/li&gt;
                {% endif %}
                {% set lastError = error %}
            {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}"><pre class="notranslate"><code class="notranslate">{% block field_errors %}
{% spaceless %}
    {% if errors|length &gt; 0 %}
        &lt;ul&gt;
            {% set lastError = null %}
            {% for error in errors %}
                {% if lastError != error %}
                    &lt;li&gt;{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}&lt;/li&gt;
                {% endif %}
                {% set lastError = error %}
            {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}
</code></pre></div>