Sha256: 15c3126e7ed5eb87e9044ed1490e8d25729f1e5b973df2cf0b87eb899afcdc4c

Contents?: true

Size: 991 Bytes

Versions: 8

Compression:

Stored size: 991 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_in, ->(parent_term_id) { where(:parent_term.in => parent_term_id)}
  scope :label_is, ->(label) {where(:label => label)}
  scope :fund_code_is, ->(fund_code) { where(:'term_type.FUND_CODE' => fund_code.gsub(/^0*/, ""))}

  def self.purge!
    TaxonomyTerm.destroy_all
  end

  def self.label_for_term(term_id)
    where(term_id: term_id).try(:first).try(:label)
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
daengine-0.3.7.3 app/models/taxonomy_term.rb
daengine-0.3.7.2 app/models/taxonomy_term.rb
daengine-0.3.7.1 app/models/taxonomy_term.rb
daengine-0.3.7 app/models/taxonomy_term.rb
daengine-0.3.5 app/models/taxonomy_term.rb
daengine-0.3.4 app/models/taxonomy_term.rb
daengine-0.3.3 app/models/taxonomy_term.rb
daengine-0.3.2 app/models/taxonomy_term.rb