title: Symfony - get an entity object in a field constraint class
body: <p>I created my custom constraint validator:</p>
  
  <pre><code>class CustomConstraint extends Constraint
  {
      public $message = '';
  }
  
  class CustomConstraintValidator extends ConstraintValidator
  {
      public function validate($value, Constraint $constraint)
      {
           exit($this-&gt;context-&gt;getObject()); // returns null
      }
  }
  </code></pre>
  
  <p>In <a href="http://api.symfony.com/3.0/Symfony/Component/Validator/Context/ExecutionContextInterface.html" rel="nofollow noreferrer">docs</a> it is stated that:</p>
  
  <blockquote>
    <p>Returns the currently validated object.</p>
  </blockquote>
  
  <p>, but for me it returns <code>NULL</code> instead.</p>
  
  <p>P.S. I do not want to assign this constraint to Entity, only to certain forms or fields.</p>
  
  <p>My form property which is validated:</p>
  
  <pre><code>-&gt;add('rejectReasons', null, array(
          'property' =&gt; 'name',
          'multiple' =&gt; true,
          'constraints' =&gt; array(
              new CustomConstraint(array(
                  'message' =&gt; 'Application can not be refused.'
              )),
          )
      ));
  </code></pre>
  
  <p>Property in entity:</p>
  
  <pre><code>/**
   * @ORM\ManyToMany(targetEntity="RejectReason")
   * @ORM\JoinTable(name="relationship_application_reject_reasons",
   *      joinColumns={@ORM\JoinColumn(name="application_id", referencedColumnName="id", onDelete="CASCADE")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="reject_reason_id", referencedColumnName="id")}
   *      )
   */
  private $rejectReasons;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried putting constraint on other string property, I still get <code>NULL</code>.</p>