Skip to content

A platform for community discussion. Free, open, simple.

FIX: TopicQuery category lookup by slug

Daniel Waterworth790e1b7191c4
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 1982ed133e8..5060180889b 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -640,9 +640,16 @@ class TopicQuery
end
def get_category_id(category_id_or_slug)
- return nil unless category_id_or_slug
+ return nil unless category_id_or_slug.present?
category_id = category_id_or_slug.to_i
- category_id = Category.where(slug: category_id_or_slug).pluck_first(:id) if category_id == 0
+
+ if category_id == 0
+ category_id =
+ Category
+ .where(slug: category_id_or_slug, parent_category_id: nil)
+ .pluck_first(:id)
+ end
+
category_id
end