2015-08-11 16:52:04 +08:00
|
|
|
|
class ForgeMessage < ActiveRecord::Base
|
2015-09-28 17:31:55 +08:00
|
|
|
|
# status在不同的类中,作用不同
|
|
|
|
|
# Isseu: satus nil:发布了缺陷;:1:缺陷计划完成日志到了提醒
|
|
|
|
|
attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key, :status
|
2015-08-11 16:52:04 +08:00
|
|
|
|
|
|
|
|
|
belongs_to :forge_message ,:polymorphic => true
|
|
|
|
|
belongs_to :project
|
|
|
|
|
belongs_to :user
|
2015-08-24 22:47:48 +08:00
|
|
|
|
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
|
|
|
|
|
2015-08-11 16:52:04 +08:00
|
|
|
|
validates :user_id,presence: true
|
|
|
|
|
validates :project_id,presence: true
|
|
|
|
|
validates :forge_message_id,presence: true
|
|
|
|
|
validates :forge_message_type, presence: true
|
2015-08-24 22:47:48 +08:00
|
|
|
|
after_create :add_user_message
|
2015-08-24 17:51:19 +08:00
|
|
|
|
|
2015-08-24 22:47:48 +08:00
|
|
|
|
def add_user_message
|
2015-09-06 11:55:20 +08:00
|
|
|
|
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
|
2015-08-24 17:51:19 +08:00
|
|
|
|
end
|
2015-08-11 16:52:04 +08:00
|
|
|
|
end
|