agenda-libre-ruby/app/models/region.rb

22 lines
580 B
Ruby
Raw Normal View History

# This is mostly to group events around a region
class Region < ApplicationRecord
belongs_to :region
2017-09-17 11:14:49 +02:00
has_many :regions, dependent: :nullify
2017-09-17 11:14:49 +02:00
has_many :orgas, dependent: :destroy
2014-01-02 00:21:49 +01:00
default_scope { order :name }
scope :top, ->(*) { where(region: nil).includes(:regions).reorder :code }
scope :local, ->(*) { where(url: nil).or(Region.where(url: '')) }
2018-03-18 16:05:26 +01:00
scope :region, (lambda do |region|
return if region.nil? || region == 'all' || region.to_i.zero?
2018-09-15 15:05:21 +02:00
2018-03-18 16:05:26 +01:00
temp = Region.find region
where region: [temp, temp.regions].flatten
end)
2014-06-09 12:18:40 +02:00
def to_s
name
end
2013-12-03 21:56:20 +01:00
end