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.
|
|
|
|
#encoding: utf-8
|
|
|
|
|
class CompetitionTeam < ActiveRecord::Base
|
|
|
|
|
belongs_to :user
|
|
|
|
|
belongs_to :competition
|
|
|
|
|
|
|
|
|
|
has_many :team_members, :dependent => :destroy
|
|
|
|
|
has_many :members, conditions: 'team_members.is_teacher = 0', class_name: 'TeamMember'
|
|
|
|
|
has_many :teachers, conditions: 'team_members.is_teacher = 1', class_name: 'TeamMember'
|
|
|
|
|
has_many :competition_scores, :dependent => :destroy
|
|
|
|
|
# team_type 0:组队 1:个人
|
|
|
|
|
# attr_accessible :invite_code, :name, :team_type
|
|
|
|
|
|
|
|
|
|
def teacher
|
|
|
|
|
User.where(:id => self.teacher_id).first
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def group_members
|
|
|
|
|
str = ""
|
|
|
|
|
self.team_members.where(:is_teacher => 0).joins("join users on team_members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci asc").each do |member|
|
|
|
|
|
str = str == "" ? member.user.show_real_name : (str + "、" + member.user.show_real_name)
|
|
|
|
|
end
|
|
|
|
|
str
|
|
|
|
|
end
|
|
|
|
|
end
|