Created
September 5, 2013 09:37
-
-
Save ljkbennett/6448027 to your computer and use it in GitHub Desktop.
Recorded for posterity
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
scope :for_region, lambda { |region| | |
joins("LEFT OUTER JOIN blog_post_shared_regions ON blog_post_shared_regions.blog_post_id = blog_posts.id") | |
.where("blog_posts.region_id = ? OR (blog_post_shared_regions.region_id = ? AND blog_post_shared_regions.visible = true)", region.id, region.id) | |
.order( "CASE WHEN blog_post_shared_regions.shared_at IS NULL THEN blog_posts.updated_at WHEN blog_post_shared_regions.shared_at > blog_posts.updated_at THEN blog_post_shared_regions.shared_at ELSE blog_posts.updated_at END DESC") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment