I have a problem, while deleting an entry in a m:n-table. I tried this solution, but I get the error: "ContextErrorException: Catchable Fatal Error: Argument 1 passed to Pso\ProjectBundle\Entity\Project::removeUser() must be an instance of Pso\LogBundle\Entity\User, string given, called in C:\xampp\htdocs\pso\src\Pso\ProjectBundle\Controller\ProjectController.php on line 59 and defined in C:\xampp\htdocs\pso\src\Pso\ProjectBundle\Entity\Project.php line 452"
I have a Class Project with the function:
/**
* Remove users
*
* @param \Pso\LogBundle\Entity\User $users
*/
public function removeUser(\Pso\LogBundle\Entity\User $users)
{
$this->users->removeElement($users);
}
Now I want to delete an entry from the table project_user. This table implements the n:m-relationship from user and project
Im my Controller I tried to adapt the linked solution:
public function deleteUserProjectAction($id, $projectid, Request $request)
{
$em = $this->getDoctrine()->getManager();
$project = $em->find('PsoProjectBundle:Project', $projectid);
$project->removeUser($id);
$em->persist($project);
$em->flush();
}
$id is the id of the user in the n:m table and $projectid the related project. Any hint for solution would be appreciated.