FIX: order latest was broken

This commit is contained in:
Sam 2015-09-18 17:16:37 +10:00
parent a4ace3f08e
commit 664e2209e5
1 changed files with 5 additions and 3 deletions

View File

@ -522,11 +522,13 @@ class Search
def aggregate_search(opts = {})
min_or_max = @order == :latest ? "max" : "min"
post_sql = posts_query(@limit, aggregate_search: true,
private_messages: opts[:private_messages])
.select('topics.id', 'min(post_number) post_number')
.group('topics.id')
.to_sql
.select('topics.id', "#{min_or_max}(post_number) post_number")
.group('topics.id')
.to_sql
# double wrapping so we get correct row numbers
post_sql = "SELECT *, row_number() over() row_number FROM (#{post_sql}) xxx"