数据库修改以及一对一,一对多,多对多等关系的确立

This commit is contained in:
sw 2015-11-13 15:47:39 +08:00
parent bbf087fa67
commit 466f3c4cc3
12 changed files with 70 additions and 16 deletions

View File

@ -3,5 +3,5 @@ class Exercise < ActiveRecord::Base
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 #该文件被哪些用户提交答案过
has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过
end

View File

@ -4,5 +4,5 @@ class ExerciseAnswer < ActiveRecord::Base
belongs_to :user
belongs_to :exercise_question
belongs_to :exercise_choices
belongs_to :exercise_choice
end

View File

@ -1,4 +1,4 @@
class ExerciseChoices < ActiveRecord::Base
class ExerciseChoice < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :exercise_question

View File

@ -2,7 +2,7 @@ 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_choices, :order => "#{ExerciseChoice.table_name}.choice_position",:dependent => :destroy
has_many :exercise_answers, :dependent => :destroy
has_many :exercise_standard_answers, :dependent => :destroy
end

View File

@ -3,5 +3,5 @@ class ExerciseStandardAnswer < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :exercise_question
belongs_to :exercise_choices
belongs_to :exercise_choice
end

View File

@ -82,10 +82,10 @@ class User < Principal
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 :exercise_user, :dependent => :destroy #答卷中间表
has_many :exercise_answer, :dependent => :destroy #针对每个题目学生的答案
has_many :exercises, :dependent => :destroy #创建的试卷
has_many :exercises_answers, :source => :exercises, :through => :exercise_users, :dependent => :destroy #用户已经完成问答的试卷
has_many :exercises_answers, :source => :exercise, :through => :exercise_user, :dependent => :destroy #用户已经完成问答的试卷
#end
#作业相关关系
has_many :homework_commons, :dependent => :destroy

View File

@ -1,6 +1,6 @@
class Exercise < ActiveRecord::Migration
def up
create_table :exercise do |t|
create_table :exercises do |t|
t.string :exercise_name
t.text :exercise_description
t.integer :course_id

View File

@ -1,6 +1,6 @@
class ExerciseQuestion < ActiveRecord::Migration
def up
create_table :exercise_question do |t|
create_table :exercise_questions do |t|
t.string :question_title
t.integer :question_type
t.integer :question_number

View File

@ -1,8 +1,8 @@
class ExerciseStandardAnswer < ActiveRecord::Migration
def up
create_table :exercise_standard_answer do |t|
create_table :exercise_standard_answers do |t|
t.integer :exercise_question_id
t.integer :exercise_choices_id
t.integer :exercise_choice_id
t.text :answer_text
t.timestamps
end

View File

@ -1,9 +1,9 @@
class ExerciseAnswer < ActiveRecord::Migration
def up
create_table :exercise_answer do |t|
create_table :exercise_answers do |t|
t.integer :user_id
t.integer :exercise_question_id
t.integer :exercise_choices_id
t.integer :exercise_choice_id
t.text :answer_text
t.timestamps
end

View File

@ -1,6 +1,6 @@
class UserExercise < ActiveRecord::Migration
def up
create_table :exercise_user do |t|
create_table :exercise_users do |t|
t.integer :user_id
t.integer :exercise_id
t.integer :score

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151112072948) do
ActiveRecord::Schema.define(:version => 20151113025751) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -572,6 +572,60 @@ ActiveRecord::Schema.define(:version => 20151112072948) do
add_index "enumerations", ["id", "type"], :name => "index_enumerations_on_id_and_type"
add_index "enumerations", ["project_id"], :name => "index_enumerations_on_project_id"
create_table "exercise_answers", :force => true do |t|
t.integer "user_id"
t.integer "exercise_question_id"
t.integer "exercise_choices_id"
t.text "answer_text"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "exercise_choices", :force => true do |t|
t.integer "exercise_question_id"
t.text "choice_text"
t.integer "choice_position"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "exercise_questions", :force => true do |t|
t.string "question_title"
t.integer "question_type"
t.integer "question_number"
t.integer "exercise_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "exercise_standard_answers", :force => true do |t|
t.integer "exercise_question_id"
t.integer "exercise_choices_id"
t.text "answer_text"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "exercise_users", :force => true do |t|
t.integer "user_id"
t.integer "exercise_id"
t.integer "score"
t.datetime "start_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "exercises", :force => true do |t|
t.string "exercise_name"
t.text "exercise_description"
t.integer "course_id"
t.integer "exercise_status"
t.integer "user_id"
t.integer "time"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "first_pages", :force => true do |t|
t.string "web_title"
t.string "title"