socialforge/app/models/applied_message.rb

23 lines
884 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 AppliedMessage < ActiveRecord::Base
# status: 0表示未批准 status1表示已批准 status 2表示已拒绝; status: 3撤销
attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed, :applied_user_id, :role, :project_id, :name
belongs_to :applied ,:polymorphic => true
belongs_to :apply_add_schools
belongs_to :user
has_many :message_alls, :class_name => 'MessageAll', :as =>:message, :dependent => :destroy
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