socialforge/app/models/applied_message.rb

23 lines
884 B
Ruby
Raw Normal View History

2016-07-27 10:46:48 +08:00
class AppliedMessage < ActiveRecord::Base
2016-12-16 11:01:58 +08:00
# status: 0表示未批准 status1表示已批准 status 2表示已拒绝; status: 3撤销
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
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