phpmysqlsymfonydoctrine

I'm getting the wrong data when using doctrine in symfony


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): enter image description here

When I look at the queries it ran...:

enter image description here

...and rerun them...:

enter image description here

...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.

enter image description here


Solution

  • Having MySql generate the many-to-many relationship helped doctrine generate the correct entities.