2016-07-27 10:46:48 +08:00
|
|
|
|
class AppliedMessage < ActiveRecord::Base
|
|
|
|
|
# status: 0表示未批准; status:1表示已批准; status: 2表示已拒绝
|
2016-07-29 22:05:56 +08:00
|
|
|
|
|
2016-07-29 21:45:52 +08:00
|
|
|
|
attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed, :applied_user_id, :role, :project_id, :name
|
|
|
|
|
belongs_to :applied ,:polymorphic => true
|
2016-07-27 10:46:48 +08:00
|
|
|
|
belongs_to :apply_add_schools
|
|
|
|
|
belongs_to :user
|
2016-07-27 11:20:12 +08:00
|
|
|
|
has_many :message_alls, :class_name => 'MessageAll', :as =>:message, :dependent => :destroy
|
2016-07-27 10:46:48 +08:00
|
|
|
|
|
|
|
|
|
validates :user_id,presence: true
|
|
|
|
|
validates :applied_id,presence: true
|
|
|
|
|
validates :applied_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.message_alls << MessageAll.new(:user_id => self.user_id, :viewed => false)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|