diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 4a9b823f92e..a2275b89e5f 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -289,8 +289,8 @@ class TopicQuery def list_category_topic_ids(category) query = default_results(category: category.id) - pinned_ids = query.where('pinned_at IS NOT NULL AND category_id = ?', category.id).limit(nil).order('pinned_at DESC').pluck(:id) - non_pinned_ids = query.where('pinned_at IS NULL OR category_id <> ?', category.id).pluck(:id) + pinned_ids = query.where('topics.pinned_at IS NOT NULL AND topics.category_id = ?', category.id).limit(nil).order('pinned_at DESC').pluck(:id) + non_pinned_ids = query.where('topics.pinned_at IS NULL OR topics.category_id <> ?', category.id).pluck(:id) (pinned_ids + non_pinned_ids) end