title: Symfony2 FOSUserBundle Invitation : only work on owning side associations
body: <p>Entity/User
  
  
  <pre><code>namespace My\SampleBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="fos_user")
   */
  class User extends \FOS\UserBundle\Entity\User
  {
      /** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue(strategy="AUTO") */
      protected $id;
  
      /**
       * @ORM\OneToOne(targetEntity="Invitation", inversedBy="user")
       * @ORM\JoinColumn(referencedColumnName="code")
       * @Assert\NotNull(message="Your invitation is wrong")
       */
      protected $invitation;
  
      public function setInvitation(Invitation $invitation)
      {
          $this-&gt;invitation = $invitation;
      }
  
      public function getInvitation()
      {
          return $this-&gt;invitation;
      }
  }
  </code></pre>
  
  <p>Entity/Invitation</p>
  
  <p>
  
  <pre><code>namespace My\SampleBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /** @ORM\Entity */
  class Invitation
  {
      /** @ORM\OneToOne(targetEntity="User", mappedBy="invitation", cascade={"persist", "merge"}) */
      protected $user;
  
      /** @ORM\Id @ORM\Column(type="string", length=6) */
      protected $code;
  
      /** @ORM\Column(type="string", length=256) */
      protected $email;
  
      /**
       * When sending invitation be sure to set this value to `true`
       *
       * It can prevent invitations from being sent twice
       *
       * @ORM\Column(type="boolean")
       */
      protected $sent = false;
  
      public function __construct()
      {
          // generate identifier only once, here a 6 characters length code
          $this-&gt;code = substr(md5(uniqid(rand(), true)), 0, 6);
      }
  
      public function getCode()
      {
          return $this-&gt;code;
      }
  
      public function getEmail()
      {
          return $this-&gt;email;
      }
  
      public function setEmail($email)
      {
          $this-&gt;email = $email;
      }
  
      public function isSent()
      {
          return $this-&gt;sent;
      }
  
      public function send()
      {
          $this-&gt;sent = true;
      }
  
      public function getUser()
      {
          return $this-&gt;user;
      }
  
      public function setUser(User $user)
      {
          $this-&gt;user = $user;
      }
  
      /**
       * Set code
       *
       * @param string $code
       * @return Invitation
       */
      public function setCode($code)
      {
          $this-&gt;code = $code;
  
          return $this;
      }
  
      /**
       * Set sent
       *
       * @param boolean $sent
       * @return Invitation
       */
      public function setSent($sent)
      {
          $this-&gt;sent = $sent;
  
          return $this;
      }
  
      /**
       * Get sent
       *
       * @return boolean 
       */
      public function getSent()
      {
          return $this-&gt;sent;
      }
  }
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>You cannot search for the association field
    'My\SampleBundle\Entity\Invitation#user',  because it is the inverse
    side of an association.   Find methods only work on owning side
    associations. 500 Internal Server Error - ORMException</p>
  </blockquote>
  
  <p>I am the stage which just performed the documentation.  </p>
  
  <blockquote>
    <p><a href="https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/adding_invitation_registration.md" rel="nofollow noreferrer">https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/adding_invitation_registration.md</a></p>
  </blockquote>
  
  <p>The display of the bundle is normal. However, It has become an error if I submit registration form.</p>
  
  <p>Any help?</p>
  
  <p>EDIT:</p>
  
  <p>Actually, I had set up 'inversedBy' at first.<br>
  A pre-question.<br>
  <a href="https://stackoverflow.com/questions/13149930/symfony2-fosuserbundle-invitation-inversedby-mapping-errors">Symfony2 FOSUserBundle Invitation : &#39;inversedBy&#39; mapping errors</a><br>
  On the surface, it does work. However, mapping errors is displayed by profiler. </p>
  
  <blockquote>
    <p>My\SampleBundle\Entity\Invitation# does not contain the required
    'inversedBy' attribute.</p>
  </blockquote>
  
  <p>so, I changed it in response to advice.
  I don't know what to think of it.</p>