<p dir="auto">For instance, we have 2 entities: <code class="notranslate">Website</code> and <code class="notranslate">Domain</code>.<br>
<code class="notranslate">Website</code> have a <code class="notranslate">OneToMany</code> relation to <code class="notranslate">Domain</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@ORM\OneToMany(targetEntity=&quot;Domain&quot;, mappedBy=&quot;domain&quot;, cascade={&quot;all&quot;}, orphanRemoval=true)
@Assert\Valid"><pre class="notranslate"><code class="notranslate">@ORM\OneToMany(targetEntity="Domain", mappedBy="domain", cascade={"all"}, orphanRemoval=true)
@Assert\Valid
</code></pre></div>
<p dir="auto">And <code class="notranslate">Domain</code> have a ManyToOne relation and a unique constraint on the domain name field:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@UniqueEntity(&quot;name&quot;, message=&quot;Domain already exists.&quot;)

@ORM\Column(name=&quot;name&quot;, type=&quot;string&quot;, unique=true)
@Assert\NotBlank(message = &quot;Domain required.&quot;)
$name

@ORM\ManyToOne(targetEntity=&quot;Website&quot;, inversedBy=&quot;domains&quot;)
@ORM\JoinColumn(name=&quot;website_id&quot;, referencedColumnName=&quot;id&quot;, nullable=false)
@Assert\NotBlank(message = &quot;Website required.&quot;)
$website"><pre class="notranslate"><code class="notranslate">@UniqueEntity("name", message="Domain already exists.")

@ORM\Column(name="name", type="string", unique=true)
@Assert\NotBlank(message = "Domain required.")
$name

@ORM\ManyToOne(targetEntity="Website", inversedBy="domains")
@ORM\JoinColumn(name="website_id", referencedColumnName="id", nullable=false)
@Assert\NotBlank(message = "Website required.")
$website
</code></pre></div>
<p dir="auto">I have 2 forms: <code class="notranslate">WebsiteType</code> and <code class="notranslate">DomainType</code>.<br>
<code class="notranslate">WebsiteType</code> have a CollectionType of DomainType:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$builder
    -&gt;add('domains', CollectionType::class, array(
        'entry_type'   =&gt; DomainType::class,
        'allow_add'    =&gt; true,
        'allow_delete' =&gt; true,
        'by_reference' =&gt; false,
    ))
;"><pre class="notranslate"><code class="notranslate">$builder
    -&gt;add('domains', CollectionType::class, array(
        'entry_type'   =&gt; DomainType::class,
        'allow_add'    =&gt; true,
        'allow_delete' =&gt; true,
        'by_reference' =&gt; false,
    ))
;
</code></pre></div>
<p dir="auto">I can save a new website with domains automatically created.<br>
I can update website and domains in the same form too.</p>
<p dir="auto">The problem is on an update, if we do not send domains in the same order then they have been saved, it will raise an error on the <code class="notranslate">Domain</code> unique constraint.</p>
<p dir="auto">Example:<br>
Create a new website with 2 domains:</p>
<ul dir="auto">
<li>domain[0][name] = domain1.com</li>
<li>domain[1][name] = domain2.com</li>
</ul>
<p dir="auto">Save it: OK</p>
<p dir="auto">Update the website on the same form (changing domain order):</p>
<ul dir="auto">
<li>domain[0][name] = newdomain.com</li>
<li>domain[1][name] = domain1.com</li>
</ul>
<p dir="auto">Save it: ERROR: Unique constraint on domain name, domain1.com already exist</p>
<p dir="auto">Update the website on the same form (without changing order):</p>
<ul dir="auto">
<li>domain[0][name] = domain1.com</li>
<li>domain[1][name] = newdomain.com</li>
</ul>
<p dir="auto">Save it: OK</p>
<p dir="auto">I am coding a project along the lines of the cookbook entry on embedded collections as stated on: <a href="http://symfony.com/doc/current/cookbook/form/form_collections.html" rel="nofollow">http://symfony.com/doc/current/cookbook/form/form_collections.html</a>.</p>
<p dir="auto">I am considering the following use case:</p>
<ol dir="auto">
<li>Starting out with entering a new entity task, tag is the embedded collection</li>
<li>I click the Javascript 'add a tag'-link, which adds a bar 0 instance of the tag form</li>
<li>I click the Javascript 'add a tag'-link, which adds a bar 1 instance of the tag form</li>
<li>I click the Javascript 'add a tag'-link, which adds a bar 2 instance of the tag form</li>
<li>I click the Javascript 'delete this tag'-link for tag(1), which leaves me with the instances 0 and 2</li>
</ol>
<p dir="auto">Now, if I would leave all these tags blank (with a notblank validation on the tag name attribute), the returned form would be expected to visualize the error statements on instances 0 and 2. However, it turns out that the feedback is only displayed for instance 0.</p>
<p dir="auto">If I change the returned form with firebug and set the instances on the name input field of instance 2 to '1', the feedback is displayed on the correct instance. This behavior indicates a mismatch between the indexing of the embedded form instances and the validators.</p>