The :include parameter tells Rails to fetch each comment's article using a LEFT OUTER JOIN, so we won't have to look it up later.

Unfortunately, in this case, :include doesn't work. Typo stores articles and comments in the same table, which breaks :include very badly. Rails isn't smart enough to keep the two uses of the same table straight.

To work around this problem, we need to build a horrible database query by hand:

Article.find_by_sql([<

This returns a list of articles, one for each comment, with extra comment_author and comment_id fields. We then loop over the articles normally to render them.

Good news, Eric. Looks like the typo developers have changed their data model. Your original solution works with 2.6.0 (that’s the only one I’ve tested with); there’s no need for the hand-crafted query anymore!