I trying to find the best way to do the following and I’ll use a blog
with comments for an example.
Blog has many comments
Comments belongs to blog
My question is how to limit the number of comments (child) records read
for each blog (parent) record. Most of the solutions I’ve come up with
are limiting the number of records displayed within the views but the
select statement on the comments table still gets all of them. My goal
is to only show the 10 most recent comments for the blog entry if there
are X + 10 comments, but I still want to be able to display all comments
if the user chooses to. I want to retrieve the least amount of records
possible to save on performance.
I’m stumped on where to implement this. In the model? The controller?
And still make it DRY enough.
Any thoughts would be greatly appreciated.