Sha256: 4109f88f412fb12abd01fdf8d97cc0a660a4ff2c5ccf3d7d8b65bb7231ea419f

Contents?: true

Size: 789 Bytes

Versions: 5

Compression:

Stored size: 789 Bytes

Contents

require 'mongoid'

class TaxonomyTerm
  include Mongoid::Document
  include Mongoid::Timestamps

  field :label, type: String
  field :term_id, type: String
  field :term_type, :type => Hash, :default => {}

  key :term_id
  has_and_belongs_to_many :child_terms, :class_name => 'TaxonomyTerm', :inverse_of => :parent_term
  belongs_to :parent_term, :class_name => 'TaxonomyTerm', :inverse_of => :child_terms

  #validations
  validates_presence_of :term_id, :label
  validates_uniqueness_of :term_id

  scope :term_id_is, ->(term_id) { where(:term_id => term_id)}
  scope :parent_term_is, ->(parent_term_id) { where(:parent_term => parent_term_id)}
  scope :label_is, ->(label) {where(:label => label)}

  def self.purge!
    TaxonomyTerm.destroy_all
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
daengine-0.2.7 app/models/taxonomy_term.rb
daengine-0.2.5 app/models/taxonomy_term.rb
daengine-0.2.4 app/models/taxonomy_term.rb
daengine-0.2.3 app/models/taxonomy_term.rb
daengine-0.2.2 app/models/taxonomy_term.rb