socialforge/app/models/contest_message.rb

24 lines
978 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ContestMessage < ActiveRecord::Base
# Workstatus
# 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