Sha256: eab3e6cb9b162840c3b832618adc57c76fc9341e621863339a6dee6c47dbbde3
Contents?: true
Size: 977 Bytes
Versions: 12
Compression:
Stored size: 977 Bytes
Contents
module Pulitzer class Tag < Pulitzer::ApplicationRecord has_many :post_tags, as: :label, dependent: :destroy, inverse_of: :label has_many :partial_tags, as: :label, dependent: :destroy, inverse_of: :label has_many :versions, through: :post_tags has_many :posts, through: :versions has_many :active_versions, -> { active }, through: :post_tags, source: :version has_many :active_posts, through: :active_versions, source: :post has_many :children, class_name: 'Pulitzer::Tag', dependent: :destroy, foreign_key: :parent_id belongs_to :parent, class_name: 'Pulitzer::Tag', touch: true validates :name, presence: true, uniqueness: true scope :hierarchical, -> { where hierarchical: true } scope :flat, -> { where hierarchical: false } scope :root, -> { hierarchical.where(parent_id: nil) } def self.named(name = "") find_by name: name end def root? hierarchical? && parent_id.nil? end end end
Version data entries
12 entries across 12 versions & 1 rubygems