A simple task: given that there are many comments in the article, you can display the number of comments of each article in a long list of articles. I am trying to figure out how to preload this data with Arel.
The Integrated Aggregations section of the README file seems to discuss this type of situation, but it certainly does not offer sample code, nor does it offer a way to do this in two queries instead of a single combined query, which is worse for performance.
Given the following:
class Article
has_many :comments
end
class Comment
belongs_to :article
end
How can I preload the article, how many comments do each have?
source
share