title: Symfony validation only on new form
body: <p>My validation works for creating a new entity, and not allowing a duplicate description.</p>
  <p>How do I make this validation work for updating an entity, as it is, when updating the entity the validator is invoked and displays an error.</p>
  <p>I'm still learning Symfony so please let me know any further details I need to provide.</p>
  <p>descUnique.php</p>
  <pre><code>
  use Symfony\Component\Validator\Constraint;
  
  /**
   * @Annotation
   */
  class descUnique extends Constraint
  {
      public $message = 'The description &quot;{{ value }}&quot; is allready in use.';
  }
  </code></pre>
  <p>descUniqueValidator.php</p>
  <pre><code>class descUniqueValidator extends ConstraintValidator {
  
      /**
       * @var Security
       */
      private $security;
  
      /**
       * @var Em
       */
      private $em;
  
      public function __construct(EntityManagerInterface $em, Security $security) {
          $this-&gt;em = $em;
          $this-&gt;security = $security;
      }
  
      public function validate($value, Constraint $constraint) {
          /* @var $constraint \App\Validator\descUnique */
  
          if (null === $value || '' === $value) {
              return;
          }
  
          $repo = $this-&gt;em-&gt;getRepository(Carrier::class)
                  -&gt;findUniqueName($this-&gt;security-&gt;getUser(), $value);
  
          
          if ($repo) {
              $this-&gt;context-&gt;buildViolation($constraint-&gt;message)
                      -&gt;setParameter('{{ value }}', $value)
                      -&gt;addViolation();
          }
      }
  
  }
  </code></pre>
  <p><strong>edit</strong></p>
  <p>My validator declaration in the entity object.</p>
  <pre><code>    /**
       * @ORM\Column(type=&quot;string&quot;, length=100)
       * @Validator\CarrierDescUnique
       */
      private $description;
  </code></pre>