school表done

建立了school和course的一对多关联
This commit is contained in:
Wen 2014-03-20 16:19:16 +08:00
parent 0b1ec7a1c5
commit 337885503e
8 changed files with 34 additions and 12 deletions

View File

@ -4,6 +4,7 @@ class Course < ActiveRecord::Base
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password 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 :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 :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 has_many :bid
validates_presence_of :password, :term validates_presence_of :password, :term
safe_attributes 'extra', safe_attributes 'extra',

4
app/models/school.rb Normal file
View File

@ -0,0 +1,4 @@
class School < ActiveRecord::Base
attr_accessible :name, :province
has_many :courses
end

View File

@ -1,5 +0,0 @@
class RemoveCityFromSchools < ActiveRecord::Migration
def change
remove_column :schools, :city
end
end

View File

@ -1,12 +1,10 @@
class CreateSchools < ActiveRecord::Migration class CreateSchools < ActiveRecord::Migration
def change def change
create_table :schools do |t| create_table :schools do |t|
t.string :name t.string :name
t.string :province t.string :province
t.string :city
end
end
t.timestamps
end
end
end end

View File

@ -0,0 +1,5 @@
class AddSchoolidToCourses < ActiveRecord::Migration
def change
add_column :courses, :school_id, :integer
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -173,6 +173,7 @@ ActiveRecord::Schema.define(:version => 20140319092720) do
t.string "setup_time" t.string "setup_time"
t.string "endup_time" t.string "endup_time"
t.string "class_period" t.string "class_period"
t.integer "school_id"
end end
create_table "custom_fields", :force => true do |t| create_table "custom_fields", :force => true do |t|
@ -600,6 +601,8 @@ ActiveRecord::Schema.define(:version => 20140319092720) do
create_table "schools", :force => true do |t| create_table "schools", :force => true do |t|
t.string "name" t.string "name"
t.string "province" t.string "province"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end end
create_table "seems_rateable_cached_ratings", :force => true do |t| create_table "seems_rateable_cached_ratings", :force => true do |t|

9
test/fixtures/schools.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name:
province: MyString
two:
name:
province: MyString

7
test/unit/school_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class SchoolTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end