From 337885503e5d07744623f326e0ec625e2d6198fd Mon Sep 17 00:00:00 2001 From: Wen Date: Thu, 20 Mar 2014 16:19:16 +0800 Subject: [PATCH] =?UTF-8?q?school=E8=A1=A8done=20=E5=BB=BA=E7=AB=8B?= =?UTF-8?q?=E4=BA=86school=E5=92=8Ccourse=E7=9A=84=E4=B8=80=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 1 + app/models/school.rb | 4 ++++ db/migrate/20140318072309_remove_city_from_schools.rb | 5 ----- ...reate_schools.rb => 20140320015156_create_schools.rb} | 6 ++---- db/migrate/20140320022724_add_schoolid_to_courses.rb | 5 +++++ db/schema.rb | 9 ++++++--- test/fixtures/schools.yml | 9 +++++++++ test/unit/school_test.rb | 7 +++++++ 8 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 app/models/school.rb delete mode 100644 db/migrate/20140318072309_remove_city_from_schools.rb rename db/migrate/{20140318021747_create_schools.rb => 20140320015156_create_schools.rb} (83%) create mode 100644 db/migrate/20140320022724_add_schoolid_to_courses.rb create mode 100644 test/fixtures/schools.yml create mode 100644 test/unit/school_test.rb diff --git a/app/models/course.rb b/app/models/course.rb index 5873c4f48..d2f1abfef 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -4,6 +4,7 @@ class Course < ActiveRecord::Base attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password belongs_to :project, :class_name => 'Project', :foreign_key => :extra # 定义一个project方法, 该方法通过extra来调用project表 belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 + belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 has_many :bid validates_presence_of :password, :term safe_attributes 'extra', diff --git a/app/models/school.rb b/app/models/school.rb new file mode 100644 index 000000000..7dbf5e3a8 --- /dev/null +++ b/app/models/school.rb @@ -0,0 +1,4 @@ +class School < ActiveRecord::Base + attr_accessible :name, :province + has_many :courses +end diff --git a/db/migrate/20140318072309_remove_city_from_schools.rb b/db/migrate/20140318072309_remove_city_from_schools.rb deleted file mode 100644 index c91413134..000000000 --- a/db/migrate/20140318072309_remove_city_from_schools.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveCityFromSchools < ActiveRecord::Migration - def change - remove_column :schools, :city - end -end diff --git a/db/migrate/20140318021747_create_schools.rb b/db/migrate/20140320015156_create_schools.rb similarity index 83% rename from db/migrate/20140318021747_create_schools.rb rename to db/migrate/20140320015156_create_schools.rb index 3771f3891..77cb138f8 100644 --- a/db/migrate/20140318021747_create_schools.rb +++ b/db/migrate/20140320015156_create_schools.rb @@ -1,12 +1,10 @@ class CreateSchools < ActiveRecord::Migration - def change create_table :schools do |t| t.string :name t.string :province - t.string :city + + t.timestamps end end - - end diff --git a/db/migrate/20140320022724_add_schoolid_to_courses.rb b/db/migrate/20140320022724_add_schoolid_to_courses.rb new file mode 100644 index 000000000..02fade5a7 --- /dev/null +++ b/db/migrate/20140320022724_add_schoolid_to_courses.rb @@ -0,0 +1,5 @@ +class AddSchoolidToCourses < ActiveRecord::Migration + def change + add_column :courses, :school_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index effd13d81..9584fa817 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140319092720) do +ActiveRecord::Schema.define(:version => 20140320022724) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -173,6 +173,7 @@ ActiveRecord::Schema.define(:version => 20140319092720) do t.string "setup_time" t.string "endup_time" t.string "class_period" + t.integer "school_id" end create_table "custom_fields", :force => true do |t| @@ -598,8 +599,10 @@ ActiveRecord::Schema.define(:version => 20140319092720) do end create_table "schools", :force => true do |t| - t.string "name" - t.string "province" + t.string "name" + t.string "province" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "seems_rateable_cached_ratings", :force => true do |t| diff --git a/test/fixtures/schools.yml b/test/fixtures/schools.yml new file mode 100644 index 000000000..953c725bf --- /dev/null +++ b/test/fixtures/schools.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + name: + province: MyString + +two: + name: + province: MyString diff --git a/test/unit/school_test.rb b/test/unit/school_test.rb new file mode 100644 index 000000000..e86105ea2 --- /dev/null +++ b/test/unit/school_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SchoolTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end