You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/app/models/competition.rb

36 lines
1.3 KiB

6 years ago
# encoding: utf-8
class Competition < ActiveRecord::Base
# status 0下架 1上架
attr_accessible :end_time, :identifier, :name, :online_time, :start_time, :status, :visits, :competition_lists_count,
5 years ago
:min_num, :max_num, :enroll_end_time, :sub_title
6 years ago
has_many :competition_modules, :dependent => :destroy
has_many :competition_stages, :dependent => :destroy
has_many :competition_stage_sections, :dependent => :destroy
has_many :competition_lists, :dependent => :destroy
has_many :competition_teams, :dependent => :destroy
has_many :team_members, :dependent => :destroy
has_many :chart_rules, :dependent => :destroy
has_many :competition_scores, :dependent => :destroy
has_many :competition_text_configs, :dependent => :destroy
has_many :competition_staffs, dependent: :destroy
6 years ago
acts_as_attachable
after_create :create_competition_modules
def create_competition_modules
modules = ["首页", "报名", "通知公告", "排行榜", "资料下载"]
modules.each_with_index do |name, index|
self.competition_modules << CompetitionModule.new(:name => name, :position => index + 1)
end
end
def to_param
self.identifier.present? ? identifier : id
end
def member_count
self.team_members.count + 268
end
end