-
-
Save rubiety/932081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MODEL | |
class Theater | |
named_scope :with_recent_comments, | |
:select => "*, recent_comments.created_at AS last_comment_at", | |
:joins => "INNER JOIN (SELECT id, entity_id, created_at FROM comments WHERE entity_type = 'Theater' ORDER by id DESC LIMIT 100) | |
AS recent_comments ON recent_comments.entity_id = theaters.id", | |
:order => "recent_comments.created_at DESC" | |
end | |
# CONTROLLER | |
Theater.with_recent_comments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment