diff --git a/app/models/course_stage.rb b/app/models/course_stage.rb new file mode 100644 index 000000000..27eb9de30 --- /dev/null +++ b/app/models/course_stage.rb @@ -0,0 +1,9 @@ +class CourseStage < ApplicationRecord + belongs_to :course, counter_cache: true + + has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy + has_many :shixuns, :through => :course_stage_shixuns + + validates :name, length: { maximum: 60 } + validates :description, length: { maximum: 300 } +end diff --git a/app/models/course_stage_shixun.rb b/app/models/course_stage_shixun.rb new file mode 100644 index 000000000..be5a1bb7d --- /dev/null +++ b/app/models/course_stage_shixun.rb @@ -0,0 +1,5 @@ +class CourseStageShixun < ApplicationRecord + belongs_to :course, counter_cache: :stages_count, counter_cache: :shixuns_count + belongs_to :course_stage + belongs_to :shixun, counter_cache: :shixuns_count +end diff --git a/db/migrate/20190910061807_create_course_stages.rb b/db/migrate/20190910061807_create_course_stages.rb new file mode 100644 index 000000000..c664b7f92 --- /dev/null +++ b/db/migrate/20190910061807_create_course_stages.rb @@ -0,0 +1,13 @@ +class CreateCourseStages < ActiveRecord::Migration[5.2] + def change + create_table :course_stages do |t| + t.references :course, index: true + t.string :name + t.text :description + t.integer :position + t.integer :shixuns_count + + t.timestamps + end + end +end diff --git a/db/migrate/20190910062710_create_course_stage_shixuns.rb b/db/migrate/20190910062710_create_course_stage_shixuns.rb new file mode 100644 index 000000000..04512c7da --- /dev/null +++ b/db/migrate/20190910062710_create_course_stage_shixuns.rb @@ -0,0 +1,12 @@ +class CreateCourseStageShixuns < ActiveRecord::Migration[5.2] + def change + create_table :course_stage_shixuns do |t| + t.references :course, index: true + t.references :course_stage, index: true + t.references :shixun, index: true + t.integer :position + + t.timestamps + end + end +end diff --git a/spec/models/course_stage_shixun_spec.rb b/spec/models/course_stage_shixun_spec.rb new file mode 100644 index 000000000..716af2b97 --- /dev/null +++ b/spec/models/course_stage_shixun_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseStageShixun, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/course_stage_spec.rb b/spec/models/course_stage_spec.rb new file mode 100644 index 000000000..06c711908 --- /dev/null +++ b/spec/models/course_stage_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseStage, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end