Class: Tagging

Inherits:
ApplicationRecord show all
Defined in:
app/models/tagging.rb

Overview

== Schema Information

Table name: taggings
Database name: primary

id :integer not null, primary key
context :string(255)
taggable_type :string(255)
tagger_type :string(255)
created_at :datetime
tag_id :integer
taggable_id :integer
tagger_id :integer

Indexes

index_taggings_on_context (context)
index_taggings_on_tag_id_and_taggable_type (tag_id,taggable_type)
index_taggings_on_taggable (taggable_type,taggable_id)
index_taggings_on_taggable_id_and_taggable_type_and_context (taggable_id,taggable_type,context)
index_taggings_on_taggable_id_type_and_tag_id (taggable_id,taggable_type,tag_id)
index_taggings_on_tagger_id_and_tagger_type (tagger_id,tagger_type)
taggings_idx (tag_id,taggable_id,taggable_type,context,tagger_id,tagger_type) UNIQUE
taggings_idy (taggable_id,taggable_type,tagger_id,context)

Foreign Keys

fk_rails_... (tag_id => tags.id) ON DELETE => cascade

Constant Summary collapse

TAGGABLE_TYPES =

Models that include the Taggable concern (includes STI subclasses)

%w[
  Article
  Post
  ArticleFaq
  ArticleTechnical
  ArticleTraining
  ArticleProcedure
  Showcase
  DigitalAsset
  Image
  Video
  SketchfabModel
  FloorPlanDisplay
  Item
  ProductLine
  ActivityType
  LocatorRecord
].freeze

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#tag_idObject (readonly)



55
# File 'app/models/tagging.rb', line 55

validates :tag_id, presence: true

Class Method Details

.for_tagActiveRecord::Relation<Tagging>

A relation of Taggings that are for tag. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Tagging>)

See Also:



64
# File 'app/models/tagging.rb', line 64

scope :for_tag, ->(tag) { where(tag: tag) }

.for_taggableActiveRecord::Relation<Tagging>

A relation of Taggings that are for taggable. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Tagging>)

See Also:



65
# File 'app/models/tagging.rb', line 65

scope :for_taggable, ->(taggable) { where(taggable: taggable) }

.for_typeActiveRecord::Relation<Tagging>

A relation of Taggings that are for type. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Tagging>)

See Also:



63
# File 'app/models/tagging.rb', line 63

scope :for_type, ->(type) { where(taggable_type: type) }

.taggable_typesObject

Get all distinct taggable types currently in use



68
69
70
# File 'app/models/tagging.rb', line 68

def self.taggable_types
  distinct.pluck(:taggable_type).sort
end

Instance Method Details

#tagTag

Returns:

See Also:



52
# File 'app/models/tagging.rb', line 52

belongs_to :tag, counter_cache: true

#taggableTaggable

Returns:

  • (Taggable)

See Also:



53
# File 'app/models/tagging.rb', line 53

belongs_to :taggable, polymorphic: true