I have a User table and a Library table, the relationship between them are many to many.
So I have a user_library
table.
I manage to add data to the Library table from User but I cannot recover the data afterwards.
I add them like this:
$em = $this->getDoctrine()->getManager();
$repoUser = $em->getRepository('App:User');
$user = $repoUser->findOneBy(['token' => $token_user]);
$library = new Library();
$library->setIdBook($id_book);
$user->addLibrary($library);
$em->persist($library);
$em->persist($user);
$em->flush();
I thought that simply doing: $user->getLibrary()->getIdBook()
would be enough but it is not the case.
How do you think I can get all the id_book
that match the user
?