Sha256: 2441def0a158ec0a75715e26b8c8f44e54d87f494fdcbbd8b050f8aece112053

Contents?: true

Size: 632 Bytes

Versions: 6

Compression:

Stored size: 632 Bytes

Contents

class Use < MLS::Model

  include MLS::Slugger
  # has_ltree_hierarchy

  has_many :children, class_name: 'Use', foreign_key: 'parent_id', inverse_of: :parent
  
  has_and_belongs_to_many :listings
  # has_and_belongs_to_many :properties

  def descendants(uses = nil)
    # Recursive self + children of children
    uses ||= [self]
    self.children.each do |child|
      uses << child
      uses = child.descendants(uses)
    end
    uses
  end
  
  # # Scope taken from https://github.com/RISCfuture/hierarchy/blob/master/lib/hierarchy.rb
  # def self.self_and_descendents_of(use)
  #   where("path <@ ?", use.path)
  # end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mls-1.4.0 lib/mls/use.rb
mls-1.3.0 lib/mls/use.rb
mls-1.2.0 lib/mls/use.rb
mls-1.1.4 lib/mls/use.rb
mls-1.1.3 lib/mls/use.rb
mls-1.1.2 lib/mls/use.rb