数据库的修改以及model数据关系的确定
This commit is contained in:
parent
36e0aeb301
commit
bbf087fa67
|
@ -0,0 +1,7 @@
|
|||
class Exercise < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :user
|
||||
has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number"
|
||||
has_many :exercise_users, :dependent => :destroy
|
||||
has_many :users, :through => :exercise_users #该文件被哪些用户提交答案过
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class ExerciseAnswer < ActiveRecord::Base
|
||||
#学生答题
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :exercise_question
|
||||
belongs_to :exercise_choices
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class ExerciseChoices < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise_question
|
||||
has_many :exercise_answers, :dependent => :destroy
|
||||
has_many :exercise_standard_answers, :dependent => :destroy
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class ExerciseQuestion < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise
|
||||
has_many :exercise_choiceses, :order => "#{ExerciseChoices.table_name}.choice_position",:dependent => :destroy
|
||||
has_many :exercise_answers, :dependent => :destroy
|
||||
has_many :exercise_standard_answers, :dependent => :destroy
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class ExerciseStandardAnswer < ActiveRecord::Base
|
||||
#标准答案
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise_question
|
||||
belongs_to :exercise_choices
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class ExerciseUser < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :exercise
|
||||
end
|
|
@ -81,6 +81,12 @@ class User < Principal
|
|||
has_many :poll, :dependent => :destroy #用户创建的问卷
|
||||
has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷
|
||||
# end
|
||||
#在线测验相关关系
|
||||
has_many :exercise_users, :dependent => :destroy #答卷中间表
|
||||
has_many :exercise_answers, :dependent => :destroy #针对每个题目学生的答案
|
||||
has_many :exercises, :dependent => :destroy #创建的试卷
|
||||
has_many :exercises_answers, :source => :exercises, :through => :exercise_users, :dependent => :destroy #用户已经完成问答的试卷
|
||||
#end
|
||||
#作业相关关系
|
||||
has_many :homework_commons, :dependent => :destroy
|
||||
has_many :student_works, :dependent => :destroy
|
||||
|
|
|
@ -6,8 +6,7 @@ class Exercise < ActiveRecord::Migration
|
|||
t.integer :course_id
|
||||
t.integer :exercise_status
|
||||
t.integer :user_id
|
||||
t.datetime :start_at
|
||||
t.datetime :end_at
|
||||
t.integer :time
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class ExerciseQuestion < ActiveRecord::Migration
|
|||
create_table :exercise_question do |t|
|
||||
t.string :question_title
|
||||
t.integer :question_type
|
||||
t.integer :question_number
|
||||
t.integer :exercise_id
|
||||
t.timestamps
|
||||
end
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
class UserExercise < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :user_exercise do |t|
|
||||
create_table :exercise_user do |t|
|
||||
t.integer :user_id
|
||||
t.integer :exercise_id
|
||||
t.integer :score
|
||||
t.datetime :start_at
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :user_exercise
|
||||
drop_table :exercise_user
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue