From cc23bb84d98b9d336250442e76fa7065988701a5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 3 Oct 2014 13:16:53 +1000 Subject: [PATCH] FEATURE: ninja op_likes sort for topic lists --- lib/topic_query.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index e6a168bfe..7066ab108 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -30,6 +30,7 @@ class TopicQuery # Maps `order` to a columns in `topics` SORTABLE_MAPPING = { 'likes' => 'like_count', + 'op_likes' => 'op_likes', 'views' => 'views', 'posts' => 'posts_count', 'activity' => 'bumped_at', @@ -211,6 +212,10 @@ class TopicQuery return result.references(:categories).order(TopicQuerySQL.order_by_category_sql(sort_dir)) end + if sort_column == 'op_likes' + return result.order("(SELECT like_count FROM posts p3 WHERE p3.topic_id = topics.id AND p3.post_number = 1) #{sort_dir}") + end + result.order("topics.#{sort_column} #{sort_dir}") end