Question

I’m trying to create a view that draws data from a DQL join query. I don’t have magic getters and setters, so the view script includes get method statements like $skill->getMeetingTitle() that refer to functions in the entities. When I set up the DQL statement, it doesn’t have any problem getting data from the primary table, but it won’t get data from the joined table.

// in the controller:

public function indexAction()
{
    $dql = "SELECT m, c FROM MyModule\Entity\SkillsMeetings m INNER JOIN m.category c ORDER BY c.categoryID, m.meetingID";
    $query = $this->getEntityManager()->createQuery($dql);
    $skillsList = $query->getResult();

    return array(
        'skillsList' => $skillsList,
    );
}

This works:

// in the view script:

foreach($skillsList as $skill) {
    echo $skill->getMeetingTitle() . "<br>";
}

This doesn’t work:

// in the view script:

foreach($skillsList as $skill) {
    echo $skill->getMeetingTitle() . " : ";
    echo $skill->getCategoryTitle() . "<br>";  // an element from the joined table
}

It gives the error:

Fatal error: Call to undefined method MyModule\Entity\SkillsMeetings::getCategoryTitle()
Was it helpful?

Solution

Using $skill->getCategory()->getCategoryTitle() was the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top