rails/rails — pull request #15251 by peeyushsingla (2014-05-22 18:10:40+00:00)
Title: Reorder query in active record query of rails guide 

I checked the rails guides recently and found that query in the reorder is not correct. I corrected it and pushed that yesterday and it was merged. But today there was a change i.e to move from post to article and found the same mistake.

In getting the the comments of article reordered by name there must be two things:-

Current Query:-
SELECT * FROM articles WHERE id = 10 ORDER BY name

Ideally It should be:-
SELECT * FROM articles WHERE id = 10
SELECT * FROM comments WHERE article_id = 10 ORDER BY name

1. It hit two queries on database first to load article and then comments but It is showing one.
2. Ordering is done of post but it should be of comments

Same case for default case without any reorder i.e order by posted_at :-

Current query is:-
SELECT * FROM articles WHERE id = 10 ORDER BY posted_at DESC

It should be:-

SELECT * FROM articles WHERE id = 10
SELECT * FROM comments WHERE article_id = 10 ORDER BY posted_at DESC