Tag, TagCategory & Tagging
The taxonomy models, installed by the taxonomies generator. Make any model taggable with the Taggable concern.
Tag
| Column | Type | Notes |
|---|---|---|
key | string | required, unique within its category |
name | string | required display name |
category_id | bigint | optional TagCategory |
position | integer | ordering within the category |
taggings_count | integer | counter cache |
belongs_to :category,has_many :taggings,has_many :taggables, through: :taggings- Scopes:
ordered,in_category(key),in_categories(keys)
TagCategory
| Column | Type | Notes |
|---|---|---|
key | string | required, unique |
name | string | required display name |
position | integer | ordering |
tags_count | integer | counter cache |
has_many :tags(ordered)- Scopes:
ordered,with_tags
Tagging
The polymorphic join between a Tag and any taggable record, unique per (taggable, tag) pair, with counter caches on both sides.
ruby
class Article < ApplicationRecord
include Trek::Taggable
end
article.tags << Tag.in_category("topics").first
article.tag_names # => ["Ruby"]