建立公共表
This commit is contained in:
parent
4af3c9816c
commit
7961e3db6f
|
@ -5,8 +5,15 @@ class CourseMessage < ActiveRecord::Base
|
|||
belongs_to :course_message ,:polymorphic => true
|
||||
belongs_to :course
|
||||
belongs_to :user
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :course_id,presence: true
|
||||
validates :course_message_id,presence: true
|
||||
validates :course_message_type, presence: true
|
||||
after_create :add_user_message
|
||||
|
||||
def add_user_message
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,24 +13,15 @@ class ForgeMessage < ActiveRecord::Base
|
|||
belongs_to :forge_message ,:polymorphic => true
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message
|
||||
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_save :add_user_activity
|
||||
after_create :add_user_message
|
||||
|
||||
def add_user_activity
|
||||
message_all = MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first
|
||||
if message_all
|
||||
message_all.save
|
||||
else
|
||||
message_all = MessageAll.new
|
||||
message_all.message_id = self.id
|
||||
message_all.message_type = self.class.to_s
|
||||
message_all.container_type = "Project"
|
||||
message_all.container_id = self.project_id
|
||||
message_all.save
|
||||
end
|
||||
def add_user_message
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ class Memo < ActiveRecord::Base
|
|||
receivers << self.forum.creator
|
||||
end
|
||||
# 添加发帖人
|
||||
if self.forum.creator_id != self.parent.author_id
|
||||
if self.author_id != self.parent.author_id
|
||||
receivers << self.parent.author
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,9 +3,15 @@ class MemoMessage < ActiveRecord::Base
|
|||
|
||||
belongs_to :memo
|
||||
belongs_to :user
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :forum_id,presence: true
|
||||
validates :memo_id,presence: true
|
||||
validates :memo_type, presence: true
|
||||
after_create :add_user_message
|
||||
|
||||
def add_user_message
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
class MessageAll < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :message_id, :message_type
|
||||
# 虚拟关联---项目消息表/课程消息表/用户留言消息表/贴吧消息表
|
||||
belongs_to :message ,:polymorphic => true
|
||||
# 虚拟关联---项目/课程
|
||||
belongs_to :container ,:polymorphic => true
|
||||
end
|
|
@ -3,8 +3,14 @@ class UserFeedbackMessage < ActiveRecord::Base
|
|||
|
||||
belongs_to :journals_for_message
|
||||
belongs_to :user
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :journals_for_message_id,presence: true
|
||||
validates :journals_for_message_type, presence: true
|
||||
after_create :add_user_message
|
||||
|
||||
def add_user_message
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
class CreateMessageAlls < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :message_alls do |t|
|
||||
t.string :message_type
|
||||
t.integer :user_id
|
||||
t.integer :message_id
|
||||
t.string :container_type
|
||||
t.integer :container_id
|
||||
t.string :message_type
|
||||
|
||||
t.timestamps
|
||||
end
|
41
db/schema.rb
41
db/schema.rb
|
@ -11,15 +11,14 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150824092300) do
|
||||
ActiveRecord::Schema.define(:version => 20150824133916) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
t.string "act_type", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "activity_container_id"
|
||||
t.string "activity_container_type", :default => ""
|
||||
t.datetime "created_at"
|
||||
t.integer "act_id", :null => false
|
||||
t.string "act_type", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "activity_container_id"
|
||||
t.string "activity_container_type", :default => ""
|
||||
end
|
||||
|
||||
add_index "activities", ["act_id", "act_type"], :name => "index_activities_on_act_id_and_act_type"
|
||||
|
@ -572,16 +571,6 @@ ActiveRecord::Schema.define(:version => 20150824092300) do
|
|||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "forum_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "forum_id"
|
||||
t.integer "memo_message_id"
|
||||
t.string "memo_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "forums", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.text "description"
|
||||
|
@ -885,12 +874,19 @@ ActiveRecord::Schema.define(:version => 20150824092300) do
|
|||
end
|
||||
|
||||
create_table "message_alls", :force => true do |t|
|
||||
t.string "message_type"
|
||||
t.integer "user_id"
|
||||
t.integer "message_id"
|
||||
t.string "container_type"
|
||||
t.integer "container_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "message_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "message_publics", :force => true do |t|
|
||||
t.integer "message_id"
|
||||
t.string "massage_type"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "messages", :force => true do |t|
|
||||
|
@ -1543,7 +1539,6 @@ ActiveRecord::Schema.define(:version => 20150824092300) do
|
|||
t.string "identity_url"
|
||||
t.string "mail_notification", :default => "", :null => false
|
||||
t.string "salt", :limit => 64
|
||||
t.integer "gid"
|
||||
end
|
||||
|
||||
add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id"
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
FactoryGirl.define do
|
||||
factory :message_all do
|
||||
message_type "MyString"
|
||||
message_id 1
|
||||
container_type "MyString"
|
||||
container_id 1
|
||||
end
|
||||
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe MessageAll, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue