2013-12-28 23:45:13 +01:00
|
|
|
class Event < ActiveRecord::Base
|
|
|
|
belongs_to :region, foreign_key: 'region'
|
|
|
|
|
|
|
|
scope :year, -> year {
|
|
|
|
where "end_time >= ? and start_time < ?",
|
2013-12-29 17:45:53 +01:00
|
|
|
"#{year}-1-1", "#{year.to_i+1}-1-1"
|
2013-12-28 23:45:13 +01:00
|
|
|
}
|
|
|
|
scope :month, -> year, month {
|
|
|
|
where "end_time >= ? and start_time < ?",
|
|
|
|
"#{year}-#{month.to_i-1}-1", "#{year}-#{month.to_i+2}-1"
|
|
|
|
}
|
|
|
|
scope :region, -> region { where region: region }
|
2013-12-29 20:42:00 +01:00
|
|
|
scope :tag, -> tag { where "tags like ?", "%#{tag}%" }
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|