I've got a query set up in doctrine that I'm confident does what it's supposed to...it joins several tables so we can skip a bunch of extra queries to get data through foreign keys:
$posts = $this->getDoctrine()->getManager()
->createQuery('
SELECT a AS article, COUNT(c) AS comments
FROM ArticleBundle:Article a
LEFT JOIN CommentsBundle:Comment c WITH (c.article = a.id)
LEFT JOIN ImageBundle:Image i WITH (i.id = a.image)
GROUP BY a.id
ORDER BY a.timestamp DESC
')
->getResult();
I'm able to access the data quite succesfully, like so:
{% for post in posts %}
<div id="news-story">
<div class="title">{{ post.article.title }}</div>
<div class="comments">{{ post.comments }}</div>
...
{% endfor %}
The issue is, as soon as I add a second column ("i AS image") to the field list, it fails. I get the following message...
Item "article" for "Array" does not exist in ...
...and I can't quite figure out why. I would hope that I would be able to access the variables like {{ post.article.title }} and {{ post.image.path }} (which does exist, by the way)...but I can't.
Any thoughts would be greatly appreciated.
Thanks!