diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 4f62d24c2..eae880380 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -15,6 +15,8 @@ class CourseMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + 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 diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 2d05972ab..0c8b3384f 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -22,6 +22,8 @@ class ForgeMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + 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 diff --git a/app/models/memo_message.rb b/app/models/memo_message.rb index 9be00ce14..ce3896389 100644 --- a/app/models/memo_message.rb +++ b/app/models/memo_message.rb @@ -12,6 +12,8 @@ class MemoMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + 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 diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb index 02335b8e2..db7d3a384 100644 --- a/app/models/user_feedback_message.rb +++ b/app/models/user_feedback_message.rb @@ -11,6 +11,8 @@ class UserFeedbackMessage < ActiveRecord::Base after_save :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + 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