socialforge/app/models/forge_message.rb

23 lines
883 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 ForgeMessage < ActiveRecord::Base
# status在不同的类中作用不同
# Isseu satus nil发布了缺陷1缺陷计划完成日志到了提醒
attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key, :status
belongs_to :forge_message ,:polymorphic => true
belongs_to :project
belongs_to :user
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
validates :user_id,presence: true
validates :project_id,presence: true
validates :forge_message_id,presence: true
validates :forge_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.message_alls << MessageAll.new(:user_id => self.user_id)
end
end
end