Class: GeographicArea

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping::Users
Defined in:
app/models/geographic_area.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Housekeeping::Users

#alive?, #set_created_by_id, #set_updated_by_id

Class Method Details

.ancestors_and_descendants_of(geographic_area) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/models/geographic_area.rb', line 53

def self.ancestors_and_descendants_of(geographic_area)
  where('(((geographic_areas.lft >= ?) AND (geographic_areas.lft <= ?)) OR
         ((geographic_areas.lft <= ?) AND (geographic_areas.rgt >= ?))) AND
         (geographic_areas.id != ?)',
      geographic_area.lft, geographic_area.rgt,
      geographic_area.lft, geographic_area.rgt,
      geographic_area.id).order(:lft)
end

.countriesObject



62
63
64
# File 'app/models/geographic_area.rb', line 62

def self.countries
  includes([:geographic_area_type]).where(geographic_area_types: {name: 'Country'})
end

Instance Method Details

#children_at_level1Object



66
67
68
# File 'app/models/geographic_area.rb', line 66

def children_at_level1
  GeographicArea.descendants_of(self).where('level1_id IS NOT NULL AND level2_id IS NULL')
end

#children_at_level2Object



70
71
72
# File 'app/models/geographic_area.rb', line 70

def children_at_level2
  GeographicArea.descendants_of(self).where('level2_id IS NOT NULL')
end

#descendents_of_geographic_area_type(geographic_area_type) ⇒ Object



74
75
76
# File 'app/models/geographic_area.rb', line 74

def descendents_of_geographic_area_type(geographic_area_type)
  GeographicArea.descendants_of(self).includes([:geographic_area_type]).where(geographic_area_types: {name: geographic_area_type})
end