I have a list that is pulled from three tables, Department, Type and User.
Displayed like this:
Film
student Jimmy Stewart
faculty Cary Grant
from actions.class.php
$this->departments = Doctrine_Core::getTable('Department')
->createQuery('a')
->orderBy('a.name')
->execute();
indexSuccess.php
<?php foreach ($departments as $dept): ?>
<tr>
<?php check_for_id() ?>
<td colspan="4" class="displayDept" valign="top"><?php echo $dept->getName() ?></td>
</tr>
<tr>
<?php foreach ($dept->getUsers() as $user): ?>
<tr>
<td class="displayInfo" valign="top"><?php echo $user->getType() ?></td>
<td class="displayInfo" valign="top"><a href="<?php echo $user->getUrl() ?>" target="_blank"><?php echo $user->getUrl() ?></a></td>
<td class="displayInfo" valign="top"><?php echo simple_format_text($user->getDescription()) ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
However, this results in the foreach pulling all id’s from the department table leaving some empty rows under the Department display. Like this:
Photography
student Keanu Reeves
faculty Lawrence Fishburn
Drawing
Film
student Jimmy Stewart
faculty Cary Grant
Painting
Sculpture
Can I remove the departments that do not have a user id?
UPDATE
If I am going to use a join, how do I call that in the actions? This is where I am so far, but none of my iterations are working:
$this->departments = Doctrine_Core::getTable('Department')
->createQuery('a')
->leftJoin('a.Users p')
->orderBy('a.name ASC')
->execute();
I’m not sure what it does though. I can understand the WHERE as it would be in traditional php, but I cannot follow the symfony syntax. Am I even close??
Why not do it in the query, department joined with users?
UPDATE
this is from the top of my head, but it should be something like this: