mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Tags used only on deleted topics could not be used again
This commit is contained in:
@@ -12,8 +12,17 @@ class Tag < ActiveRecord::Base
|
||||
has_many :tag_group_memberships
|
||||
has_many :tag_groups, through: :tag_group_memberships
|
||||
|
||||
COUNT_ARG = "topic_tags.id"
|
||||
|
||||
# Apply more activerecord filters to the tags_by_count_query, and then
|
||||
# fetch the result with .count(Tag::COUNT_ARG).
|
||||
#
|
||||
# e.g., Tag.tags_by_count_query.where("topics.category_id = ?", category.id).count(Tag::COUNT_ARG)
|
||||
def self.tags_by_count_query(opts={})
|
||||
q = TopicTag.joins(:tag, :topic).group("topic_tags.tag_id, tags.name").order('count_all DESC')
|
||||
q = Tag.joins("LEFT JOIN topic_tags ON tags.id = topic_tags.tag_id")
|
||||
.joins("LEFT JOIN topics ON topics.id = topic_tags.topic_id")
|
||||
.group("tags.id, tags.name")
|
||||
.order('count_topic_tags_id DESC')
|
||||
q = q.limit(opts[:limit]) if opts[:limit]
|
||||
q
|
||||
end
|
||||
@@ -37,7 +46,7 @@ class Tag < ActiveRecord::Base
|
||||
category: category
|
||||
)
|
||||
|
||||
tags.count.map {|name, _| name}
|
||||
tags.count(COUNT_ARG).map {|name, _| name}
|
||||
end
|
||||
|
||||
def self.include_tags?
|
||||
|
||||
Reference in New Issue
Block a user