2010-04-27 19 views
2

我是Rails的初學者。在下面的代碼中,有一個設置爲false的ID。它的含義是什麼?Rails create_table查詢

class CreateCoursesStudents < ActiveRecord::Migration 
    def self.up 
    create_table :courses_students, **:id => false** do |t| 
     t.integer :course_id,:null => false 
     t.integer :student_id, :null => false 
    end 
    # Add index to speed up looking up the connection, and ensure # we only 
    enrol a student into each course once 
    add_index :courses_students, [:course_id, :student_id], :unique => true 
    end 

    def self.down 
    remove_index :courses_students, :column => [:course_id, :student_id] 
    drop_table :courses_students 
    end 
end 

感謝

回答

4

:id => false定義了一個沒有主鍵的表格,這是有用的,例如,當您爲多對多關係創建連接表時。

0

:空=> false表示有關該字段不能爲獲取在該courses_students表中創建的任何行是空的。

+0

謝謝:)和create_table行中的id => false語句有什麼關係? – felix 2010-04-27 20:36:43