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/contest_message.rb

24 lines
978 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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