rendered paste body /**
* Retrieve comments with author and profile
*
* @todo: table aliases :-)
*
*/
public function getCommentsWithAuthor($culture = null)
{
if($culture === null)
{
$culture = sfContext::getInstance()->getUser()->getCulture();
}
$query = new Doctrine_Query();
$comments = $query->from('LocationComment')
->from('LocationComment.author, LocationComment.LocationCommentI18n, LocationComment.author.profile')
->where('LocationComment.LocationCommentI18n.culture = ? AND LocationComment.id = ?',
array($culture, $this->getId()))
->orderBy('LocationComment.created_at desc')
->execute();
return $comments;
}
// in my template:
<?php $comments = $location->getCommentsWithAuthor(); ?>
<?php foreach($comments as $comment): ?>
<?php $author = $comment->getAuthor(); ?>
<?php
// this is another query, why?
$profile = $author->getProfile();
?>
<?php endforeach; ?>