mirror of
https://github.com/discourse/discourse.git
synced 2025-09-10 05:01:43 +08:00
FEATURE: Adds an API to exclude a tag from a TopicQuery
To exclude a tag from a topic list, add the `exclude_tag` query parameter. For example: `latest?exclude_tag=music`
This commit is contained in:
parent
2fb9834821
commit
ae13839f98
2 changed files with 11 additions and 1 deletions
|
@ -60,7 +60,8 @@ class TopicQuery
|
|||
tags
|
||||
match_all_tags
|
||||
no_subcategories
|
||||
no_tags)
|
||||
no_tags
|
||||
exclude_tag)
|
||||
end
|
||||
|
||||
def self.valid_options
|
||||
|
@ -689,6 +690,10 @@ class TopicQuery
|
|||
# the following will do: ("topics"."id" NOT IN (SELECT DISTINCT "topic_tags"."topic_id" FROM "topic_tags"))
|
||||
result = result.where.not(id: TopicTag.distinct.pluck(:topic_id))
|
||||
end
|
||||
|
||||
if @options[:exclude_tag] && tag = Tag.find_by(name: @options[:exclude_tag])
|
||||
result = result.where.not(id: TopicTag.distinct.where(tag_id: tag.id).pluck(:topic_id))
|
||||
end
|
||||
end
|
||||
|
||||
result = apply_ordering(result, options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue