Rails create_table request

I am new to Rails. The following code has an ID that is set to false. What is the meaning of this?

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

      

thanks

+2


a source to share


2 answers


:id => false

defines a table with no primary key which is useful eg. when you create a join table for a many-to-many relationship.



+4


a source


: null => false indicates that the specified field cannot be null for any row that is created in the classes_students table.



0


a source







All Articles