Ok guys i ask you a simple question how can i set an entity who is not in parameter
I am trying this method :
$em_category = $this->getDoctrine()->getManager();
$em_category->getRepository('AppBundle:Category')->findOneBy(array('id' => ($request->get('id_category'))));
$userInterest->setUser($user);
$userInterest->setCategory($em_category);
But when i do that i have this error :
Expected value of type "AppBundle\Entity\Category" for association field "AppBundle\Entity\UserInterest#$category", got "Doctrine\ORM\EntityManager" instead.
So how can i set to userinterest the category that i want ...? Thx for all that will try to answer :p
The variably $em_category
is your entity manager, the class that performs the data storage and retrieval from the database. You need to use it to get the category, then pass that value on to setCategory
. Like so.
$cat = $em_category->getRepository('AppBundle:Category')->findOneBy(array('id' => ($request->get('id_category'))));
$userInterest->setCategory($cat);