Sha256: 1ce0db05f35db6e45d3a363680a885f6d78653df06dcb1153b2e8f4dcbf9be64
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
module ActsAsTaggableOn class Tagging < ::ActiveRecord::Base #:nodoc: #TODO, remove from 4.0.0 attr_accessible :tag, :tag_id, :context, :taggable, :taggable_type, :taggable_id, :tagger, :tagger_type, :tagger_id if defined?(ActiveModel::MassAssignmentSecurity) belongs_to :tag, class_name: 'ActsAsTaggableOn::Tag' , counter_cache: true belongs_to :taggable, polymorphic: true belongs_to :tagger, polymorphic: true scope :owned_by, ->(owner) { where(tagger: owner) } scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) } scope :by_contexts, ->(contexts = ['tags']) { where(context: contexts) } scope :by_context, ->(context= 'tags') { by_contexts(context.to_s) } validates_presence_of :context validates_presence_of :tag_id validates_uniqueness_of :tag_id, scope: [:taggable_type, :taggable_id, :context, :tagger_id, :tagger_type] after_destroy :remove_unused_tags private def remove_unused_tags if ActsAsTaggableOn.remove_unused_tags tag.destroy if tag.reload.taggings_count.zero? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
acts-as-taggable-on-3.4.1 | lib/acts_as_taggable_on/tagging.rb |
acts-as-taggable-on-3.4.0 | lib/acts_as_taggable_on/tagging.rb |
acts-as-taggable-on-3.3.0 | lib/acts_as_taggable_on/tagging.rb |