<p dir="auto">Most of the times, you define your validation rules inside of your Entities.<br>
Some Forms require only a subset of data that your Entity contains, forcing you to create FormModels and copying Validator rules from one place to the code.<br>
As everybody knows, copying means trouble and duplication, which means that if an update happens only at one location, you have an inconsistency in your code. In this situation, it'll be a missing validation rule.<br>
To mitigate this problem, Symfony Validator component should have an ability to "import" validation rules from another location (class/property). Example:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class UserUpdateFormModel
{
    /**
     * We only allow user name updates.
     *
     * @Assert\Import(from=&quot;@ICUserProfileBundle:User&quot;, property=&quot;name&quot;)
     */
    protected $name; 
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">UserUpdateFormModel</span>
{
    <span class="pl-c">/**</span>
<span class="pl-c">     * We only allow user name updates.</span>
<span class="pl-c">     *</span>
<span class="pl-c">     * @Assert\Import(from="@ICUserProfileBundle:User", property="name")</span>
<span class="pl-c">     */</span>
    <span class="pl-k">protected</span> <span class="pl-c1"><span class="pl-c1">$</span>name</span>; 
}</pre></div>
<p dir="auto">It seems to be possible already, since ClassMetadata in the validator component already has a mergeConstraints() function. What do you guys think?</p>
<p dir="auto">Hi guys,</p>
<p dir="auto">Following my discussion with leonardo I implemented a form to create a new Translation linked to an existing TranslationToken or a new one (with some ajax). For now let's focus on the case where TranslationToken exists in DataBase.</p>
<p dir="auto">Here is my relationship inside Translation class :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@ORM\ManyToOne(targetEntity=&quot;ACME\MyFirstBundle\Entity\TranslationToken&quot;)
@ORM\JoinColumns({
    @ORM\JoinColumn(name=&quot;translation_token_id&quot;, referencedColumnName=&quot;id&quot;, nullable=false)
})
private $translationToken;"><pre class="notranslate"><code class="notranslate">@ORM\ManyToOne(targetEntity="ACME\MyFirstBundle\Entity\TranslationToken")
@ORM\JoinColumns({
    @ORM\JoinColumn(name="translation_token_id", referencedColumnName="id", nullable=false)
})
private $translationToken;
</code></pre></div>
<p dir="auto">Here's how I embed a list of existing TranslationToken in my Translation Form :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            -&gt;add('translationToken', 'entity', array(
                  'label' =&gt; 'translation.translationtoken.label',
                  'class' =&gt; ACMEMyFirstBundle:TranslationToken',
                  'property' =&gt; 'name',
                  'query_builder' =&gt; function(EntityRepository $er) {
                      return $er-&gt;createQueryBuilder('tt')
                                -&gt;orderBy('tt.name', 'ASC');
                  },
                  'required' =&gt; false
                ))"><pre class="notranslate"><code class="notranslate">            -&gt;add('translationToken', 'entity', array(
                  'label' =&gt; 'translation.translationtoken.label',
                  'class' =&gt; ACMEMyFirstBundle:TranslationToken',
                  'property' =&gt; 'name',
                  'query_builder' =&gt; function(EntityRepository $er) {
                      return $er-&gt;createQueryBuilder('tt')
                                -&gt;orderBy('tt.name', 'ASC');
                  },
                  'required' =&gt; false
                ))
</code></pre></div>
<p dir="auto">So the form works fine, TranslationToken are listed correctly and TranslationToken is well attached to Translation upon $form-&gt;getData() AND after em-&gt;persist($translation) in controller :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$translation    ACME\MyFirstBundle\Entity\Translation       
id  integer 16  
language    string  &quot;en&quot;    
domain  string  &quot;messages&quot;  
message string  &quot;TEST&quot;  
translationToken    ACME\MyFirstBundle\Entity\TranslationToken      
    id  string  &quot;1&quot; 
    name    string  &quot;menu.home&quot; "><pre class="notranslate"><code class="notranslate">$translation    ACME\MyFirstBundle\Entity\Translation       
id  integer 16  
language    string  "en"    
domain  string  "messages"  
message string  "TEST"  
translationToken    ACME\MyFirstBundle\Entity\TranslationToken      
    id  string  "1" 
    name    string  "menu.home" 
</code></pre></div>
<p dir="auto">Although I select an existing TranslationToken I get the following error (maybe because the id is a string, but it's not up to me...)...</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="A new entity was found through the relationship 'ACME\MyFirstBundle\Entity\Translation#translationToken' that was not configured to cascade persist     operations for entity:     ACME\MyFirstBundle\Entity\TranslationToken@000000005b1c6e850000000070a7ede3. To solve     this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade     persist this association in the mapping for example @ManyToOne(..,cascade={&quot;persist&quot;}). If you     cannot find out which entity causes the problem implement     'PUC\LibBundle\Entity\TranslationToken#__toString()' to get a clue."><pre class="notranslate"><code class="notranslate">A new entity was found through the relationship 'ACME\MyFirstBundle\Entity\Translation#translationToken' that was not configured to cascade persist     operations for entity:     ACME\MyFirstBundle\Entity\TranslationToken@000000005b1c6e850000000070a7ede3. To solve     this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade     persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you     cannot find out which entity causes the problem implement     'PUC\LibBundle\Entity\TranslationToken#__toString()' to get a clue.
</code></pre></div>
<p dir="auto">But if I persist manually the TranslationToken object or via cascade={"persist"} it would try to INSERT a new TranslationToken in database whereas the idea is to connect the existing one to my Translation record obviously... Something you see as being wrong ? I deeply looked over the web, posted on the mailing list but nothing helped... To me it's not logical.</p>
<p dir="auto">BTW : $form-&gt;isValid() gives back an error as well for the joined field without deep details. I don't know why.</p>
<p dir="auto">Thanks for your time and consideration.</p>