Improved public_for_api scopes and corresponding specs
This commit is contained in:
@@ -21,7 +21,7 @@ module ActsAsTaggableOn
|
||||
Tag.class_eval do
|
||||
|
||||
include Graphqlable
|
||||
|
||||
|
||||
def increment_custom_counter_for(taggable_type)
|
||||
Tag.increment_counter(custom_counter_field_name_for(taggable_type), id)
|
||||
end
|
||||
@@ -45,7 +45,20 @@ module ActsAsTaggableOn
|
||||
end
|
||||
|
||||
def self.public_for_api
|
||||
where("kind IS NULL OR kind = 'category'")
|
||||
find_by_sql(%|
|
||||
SELECT *
|
||||
FROM tags
|
||||
WHERE (tags.kind IS NULL OR tags.kind = 'category') AND tags.id IN (
|
||||
SELECT tag_id
|
||||
FROM (
|
||||
SELECT COUNT(taggings.id) AS taggings_count, tag_id
|
||||
FROM ((taggings FULL OUTER JOIN proposals ON taggable_type = 'Proposal' AND taggable_id = proposals.id) FULL OUTER JOIN debates ON taggable_type = 'Debate' AND taggable_id = debates.id)
|
||||
WHERE (taggable_type = 'Proposal' AND proposals.hidden_at IS NULL) OR (taggable_type = 'Debate' AND debates.hidden_at IS NULL)
|
||||
GROUP BY tag_id
|
||||
) AS tag_taggings_count_relation
|
||||
WHERE taggings_count > 0
|
||||
)
|
||||
|)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user