asia_database/app/models/asia_project.rb

21 lines
657 B
Ruby
Raw Permalink Normal View History

2023-05-26 14:17:05 +00:00
class AsiaProject
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :project_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :start_date, :type => Date
field :end_date, :type => Date
field :sponsor, :type => String, :default => "", :localize => true
field :sort_position, type: Integer, default: 0
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({start_date: -1})}
index({start_date: -1}, { unique: false, background: true })
def date
if self.start_date.nil? && self.end_date.nil?
""
else
"#{self.start_date} ~ #{self.end_date}"
end
end
end