From baba6aa9e95d959ab445e559889d6ab8074bcc14 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Sep 2019 14:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=9C=A8=E7=BA=BF=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_stage.rb | 9 +++++++++ app/models/course_stage_shixun.rb | 5 +++++ db/migrate/20190910061807_create_course_stages.rb | 13 +++++++++++++ .../20190910062710_create_course_stage_shixuns.rb | 12 ++++++++++++ spec/models/course_stage_shixun_spec.rb | 5 +++++ spec/models/course_stage_spec.rb | 5 +++++ 6 files changed, 49 insertions(+) create mode 100644 app/models/course_stage.rb create mode 100644 app/models/course_stage_shixun.rb create mode 100644 db/migrate/20190910061807_create_course_stages.rb create mode 100644 db/migrate/20190910062710_create_course_stage_shixuns.rb create mode 100644 spec/models/course_stage_shixun_spec.rb create mode 100644 spec/models/course_stage_spec.rb 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