2016-12-22 15:08:15 +08:00
|
|
|
class AppliedContest < ActiveRecord::Base
|
|
|
|
belongs_to :contest
|
|
|
|
belongs_to :user
|
|
|
|
#status :0 新建 1 已批准 2 拒绝
|
|
|
|
attr_accessible :role, :status, :contest_id, :user_id
|
|
|
|
|
|
|
|
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
|
|
|
|
after_create :send_appliled_message
|
|
|
|
|
|
|
|
# 仅仅给项目管理人员发送消息
|
|
|
|
def send_appliled_message
|
2016-12-22 16:02:36 +08:00
|
|
|
self.contest.contest_managers.each do |member|
|
2016-12-22 15:08:15 +08:00
|
|
|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => self.role)
|
|
|
|
end
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
end
|