parent
985b3dc7ea
commit
e69e53740a
@ -0,0 +1,6 @@
|
||||
class DisciplinesController < ApplicationController
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
end
|
@ -1,3 +1,7 @@
|
||||
class Discipline < ApplicationRecord
|
||||
has_many :sub_disciplines, dependent: :destroy
|
||||
|
||||
has_many :shixun_sub_disciplines, -> { where("shixun = 1") }, class_name: "SubDiscipline"
|
||||
has_many :subject_sub_disciplines, -> { where("subject = 1") }, class_name: "SubDiscipline"
|
||||
has_many :question_sub_disciplines, -> { where("question = 1") }, class_name: "SubDiscipline"
|
||||
end
|
||||
|
@ -1,4 +1,8 @@
|
||||
class SubDiscipline < ApplicationRecord
|
||||
belongs_to :discipline
|
||||
has_many :tag_disciplines, dependent: :destroy
|
||||
|
||||
has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
|
||||
has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"
|
||||
has_many :question_tag_disciplines, -> { where("question = 1") }, class_name: "TagDiscipline"
|
||||
end
|
||||
|
@ -0,0 +1,35 @@
|
||||
case params[:source]
|
||||
when 'subject'
|
||||
disciplines = Discipline.where(subject: 1).includes(subject_sub_disciplines: :subject_tag_disciplines)
|
||||
json.disciplines disciplines do |dis|
|
||||
json.(dis, :id, :name)
|
||||
json.sub_disciplines dis.subject_sub_disciplines do |sub|
|
||||
json.(sub, :id, :name)
|
||||
json.tag_disciplines sub.subject_tag_disciplines do |tag|
|
||||
json.(tag, :id, :name)
|
||||
end
|
||||
end
|
||||
end
|
||||
when 'shixun'
|
||||
disciplines = Discipline.where(shixun: 1).includes(shixun_sub_disciplines: :shixun_tag_disciplines)
|
||||
json.disciplines disciplines do |dis|
|
||||
json.(dis, :id, :name)
|
||||
json.sub_disciplines dis.shixun_sub_disciplines do |sub|
|
||||
json.(sub, :id, :name)
|
||||
json.tag_disciplines sub.shixun_tag_disciplines do |tag|
|
||||
json.(tag, :id, :name)
|
||||
end
|
||||
end
|
||||
end
|
||||
when 'question'
|
||||
disciplines = Discipline.where(question: 1).includes(question_sub_disciplines: :question_tag_disciplines)
|
||||
json.disciplines disciplines do |dis|
|
||||
json.(dis, :id, :name)
|
||||
json.sub_disciplines dis.question_sub_disciplines do |sub|
|
||||
json.(sub, :id, :name)
|
||||
json.tag_disciplines sub.question_tag_disciplines do |tag|
|
||||
json.(tag, :id, :name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,15 @@
|
||||
class MigrateDisciplinesDefault < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column_default :disciplines, :subject, from: nil, to: 1
|
||||
change_column_default :disciplines, :shixun, from: nil, to: 1
|
||||
change_column_default :disciplines, :question, from: nil, to: 1
|
||||
|
||||
change_column_default :sub_disciplines, :subject, from: nil, to: 1
|
||||
change_column_default :sub_disciplines, :shixun, from: nil, to: 1
|
||||
change_column_default :sub_disciplines, :question, from: nil, to: 1
|
||||
|
||||
change_column_default :tag_disciplines, :subject, from: nil, to: 1
|
||||
change_column_default :tag_disciplines, :shixun, from: nil, to: 1
|
||||
change_column_default :tag_disciplines, :question, from: nil, to: 1
|
||||
end
|
||||
end
|
Loading…
Reference in new issue