gutentag icon indicating copy to clipboard operation
gutentag copied to clipboard

Ability to get tag objects for a scope

Open Antronin opened this issue 2 years ago • 1 comments

I can only find the class method

Gutentag::Tag.names_for_scope(Blog::Post)

which returns all the names of the tags for a scope (in my case Blog::Post) But if I want to display a tag cloud with the number showing how many times the tags are used, I have to use

Blog::Post.tagged_with(names: <tag_name>).count

which is very uneffective.

On a Blog::Post instance I can ask for tag objects with Blog::Post.tags and it contains the field taggings_count. I would like to get something similar for all tags of Blog::Post. Gutentag::Tag.all does not help either as it contains all tags, not just for my scope. (Not to mention that it is not documented either)

Antronin avatar Nov 24 '23 15:11 Antronin

Currently, as a workaround, I can use this:

Gutentag::Tag.joins(:taggings).where(taggings:{taggable_type: 'Blog::Post'})

Antronin avatar Nov 24 '23 16:11 Antronin