I'm trying to build a SQL query using doctrine. Here's my code snippet:
/**
* @Route("/db", name="user_skill_testing")
*/
public function dbTest()
{
//all skills for user
$userName = "Jelle";
$user = $this->getDoctrine()
->getRepository('AppBundle:User')
->findOneByFirstname($userName);
echo "userId: ".$user->getId()."<br />";
$userSkills = $this->getDoctrine()
->getRepository('AppBundle:Userskill')->findById($user->getId());
$proficiencies = array();
foreach ($userSkills as $userSkill) {
array_push($proficiencies, $userSkill);
echo $userSkill->getId();
echo "-";
echo $userSkill->getProficiency()->getId();
echo "<br />";
}
var_dump($userSkills);
$html = "<html><body>".$user->getFirstname()."<br /><br />"."</body></html>";
return new Response($html);
}
It returns the following webpage(screenshot):
When I look at the queries it ran...:
...and rerun them...:
...I get a very different result. :( I have no idea why, can anyone help me out? thank you!
Edit: using this code to build the query reproduces the same result.
Having MySql generate the many-to-many relationship helped doctrine generate the correct entities.