title: Symfony 3.4 - Expected Entity got EntityManager API REST
body: <p>I'm creating an API REST and I want to set for <code>$userInterest</code> an Entity named <code>Category</code> (<em>many to one</em>) I did the same thing for the <code>User</code> entity (<em>and I set the "Profile" entity</em>), but the <code>Profile</code> entity is passed as parameter and it's created in this function so it's simple and it works.</p>
  
  <p>I do it like this: </p>
  
  <pre><code>/**
   *
   * @Rest\Post(
   *     path = "/users/register",
   *     name = "api_users_add"
   * )
   * @Rest\View(StatusCode=201, serializerGroups={"user_detail"})
   * @ParamConverter(
   *     "user",
   *     converter="fos_rest.request_body",
   *     options={"deserializationContent"={"groups"={"Deserialize"}}},
   * )
   * @ParamConverter(
   *     "profile",
   *     converter="fos_rest.request_body",
   *     options={"deserializationContent"={"groups"={"Deserialize"}}},
   * )
   * @ParamConverter(
   *     "userInterest",
   *     converter="fos_rest.request_body",
   *     options={"deserializationContent"={"groups"={"Deserialize"}}},
   * )
   */
  public function postUserAction(Request $request, User $user, Profile 
  $profile, UserInterest $userInterest) {
  
      $profile-&gt;setLastConnexion(new \DateTime('now'));
      $profile-&gt;setCreatedAccount(new \DateTime('now'));
  
      $user-&gt;setIdProfile($profile);
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $em-&gt;persist($profile);
      $em-&gt;flush();
  
      $this-&gt;encodePassword($user);
      $user-&gt;setRoles([User::ROLE_USER]);
  
      $this-&gt;persistUser($user);
   }
  </code></pre>
  
  <p>-</p>
  
  <p>So the previus example works really well but when I try to set the <code>Category</code> entity for <code>$userInterest</code> that don't work (<em>also category is already created it's like a "static" table</em>) so the problem is how can I set <code>Category</code> for <code>$userInterest</code> knowing that in the previous example the entity is created in the function and in this example the entity is already created so I tried: </p>
  
  <pre><code>    $em_category = $this-&gt;getDoctrine()-&gt;getManager();
      $em_category-&gt;getRepository('AppBundle:Category')-&gt;findOneBy(array('id' =&gt; ($request-&gt;get('id_category'))));
  
      $userInterest-&gt;setCategory($em_category);
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $em-&gt;persist($userInterest);
      $em-&gt;flush();
  </code></pre>
  
  <p>But that makes the error:</p>
  
  <blockquote>
    <p>"Expected value of type "AppBundle\Entity\Category" for association >field "AppBundle\Entity\UserInterest#$category", got >"Doctrine\ORM\EntityManager" instead."</p>
  </blockquote>
  
  <p>How can i set the entity category and not the entity manager ...? </p>
  
  <p>The JSON sent (<em>if that can help</em>) : </p>
  
  <pre><code>{
  "username": "Usertest",
  "password": "strenghtpassword",
  "email": "thxforall@symfony.com",
  "birth": "1999-04-26T18:25:43-05:00",
  "content": "I like Netflix",
  "id_category": "1"
  }
  </code></pre>
  
  <p>In category table the ID:1 as the content "what do you like" for example.</p>