mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Support for "no subcategories"
This commit is contained in:
parent
ccd0f9c371
commit
acf262b631
14 changed files with 98 additions and 35 deletions
|
@ -17,6 +17,7 @@ class TopicQuery
|
|||
visible
|
||||
category
|
||||
sort_order
|
||||
no_subcategories
|
||||
sort_descending).map(&:to_sym)
|
||||
|
||||
# Maps `sort_order` to a columns in `topics`
|
||||
|
@ -31,7 +32,6 @@ class TopicQuery
|
|||
|
||||
def initialize(user=nil, options={})
|
||||
options.assert_valid_keys(VALID_OPTIONS)
|
||||
|
||||
@options = options
|
||||
@user = user
|
||||
end
|
||||
|
@ -209,12 +209,16 @@ class TopicQuery
|
|||
category_id = nil
|
||||
if options[:category].present?
|
||||
category_id = options[:category].to_i
|
||||
if category_id == 0
|
||||
result = result.where('categories.slug = ?', options[:category])
|
||||
else
|
||||
result = result.where('categories.id = ?', category_id)
|
||||
category_id = Category.where(slug: options[:category]).pluck(:id).first if category_id == 0
|
||||
|
||||
if category_id
|
||||
if options[:no_subcategories]
|
||||
result = result.where('categories.id = ?', category_id)
|
||||
else
|
||||
result = result.where('categories.id = ? or categories.parent_category_id = ?', category_id, category_id)
|
||||
end
|
||||
result = result.references(:categories)
|
||||
end
|
||||
result = result.references(:categories)
|
||||
end
|
||||
|
||||
result = apply_ordering(result, options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue