diff --git a/app/models/region.rb b/app/models/region.rb index 1c229c64..e7e5b2ad 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -6,6 +6,11 @@ class Region < ApplicationRecord has_many :orgas, dependent: :destroy default_scope { order :name } + scope :region, (lambda do |region| + return if region.nil? || region == 'all' || region.to_i.zero? + temp = Region.find region + where region: [temp, temp.regions].flatten + end) def to_s name