2016-01-05 16:46:06 +08:00
|
|
|
class OrgMessage < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :organization
|
2017-01-17 16:21:32 +08:00
|
|
|
has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy
|
2016-01-05 16:46:06 +08:00
|
|
|
validates :message_type, :presence => true
|
|
|
|
validates :message_id, :presence => true
|
|
|
|
validates :organization_id, :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
|