用户动态 = 参与课程动态 + 参与课程动态

表创建以及相关关系的搭建
This commit is contained in:
sw 2015-08-20 11:19:26 +08:00
parent 2f43296854
commit b52f607b68
4 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,7 @@
class UserActivity < ActiveRecord::Base
attr_accessible :act_type,:act_id,:container_type,:container_id
# 虚拟关联---项目动态表/课程动态表
belongs_to :act ,:polymorphic => true
# 虚拟关联---项目/课程
belongs_to :container ,:polymorphic => true
end

View File

@ -0,0 +1,16 @@
class CreateUserActivity < ActiveRecord::Migration
def up
create_table :user_activities do |t|
t.string :act_type
t.integer :act_id
t.string :container_type
t.integer :container_id
t.timestamps
end
end
def down
drop_table :user_activities
end
end

View File

@ -0,0 +1,37 @@
class AboutUserActivities < ActiveRecord::Migration
def up
forge_count = ForgeActivity.all.count / 30 + 2
transaction do
for i in 1 ... forge_count do i
ForgeActivity.page(i).per(30).each do |activity|
user_activity = UserActivity.new
user_activity.act_id = activity.id
user_activity.act_type = activity.class.to_s
user_activity.container_type = "Project"
user_activity.container_id = activity.project_id
user_activity.created_at = activity.created_at
user_activity.save
end
end
end
course_count = CourseActivity.all.count / 30 + 2
transaction do
for i in 1 ... course_count do i
CourseActivity.page(i).per(30).each do |activity|
user_activity = UserActivity.new
user_activity.act_id = activity.id
user_activity.act_type = activity.class.to_s
user_activity.container_type = "Course"
user_activity.container_id = activity.course_id
user_activity.created_at = activity.created_at
user_activity.save
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150815030833) do
ActiveRecord::Schema.define(:version => 20150820025358) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1394,6 +1394,15 @@ ActiveRecord::Schema.define(:version => 20150815030833) do
t.integer "fields_bits", :default => 0
end
create_table "user_activities", :force => true do |t|
t.string "act_type"
t.integer "act_id"
t.string "container_type"
t.integer "container_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_extensions", :force => true do |t|
t.integer "user_id", :null => false
t.date "birthday"