24 lines
978 B
Ruby
24 lines
978 B
Ruby
class ContestMessage < ActiveRecord::Base
|
||
# Work:status:
|
||
# nil:发布了作业; 1:截止时间到了提醒!;2:开启在线评审; 3:关闭在线评审; 4:匿评开始失败; 5:在线评审时间快到了
|
||
|
||
attr_accessible :content, :contest_message_id, :contest_message_type, :status, :viewed, :user_id, :contest_id
|
||
|
||
belongs_to :contest_message ,:polymorphic => true
|
||
belongs_to :user
|
||
belongs_to :contest
|
||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||
|
||
validates :user_id, presence: true
|
||
validates :contest_id, presence: true
|
||
validates :contest_message_id, presence: true
|
||
validates :contest_message_type, presence: true
|
||
after_create :add_user_message
|
||
|
||
def add_user_message
|
||
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9
|
||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||
end
|
||
end
|
||
end
|