2

I am a beginner in Rails. In the following code,there is an id which is set as false. What's the meaning of it?

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 Answers 2

4

:id => false defines a table with no primary key, which is useful e.g. when you create a join table for a many-to-many relationship.

Sign up to request clarification or add additional context in comments.

Comments

0

:null=>false indicates that the field in question cannot be null for any row that gets created in the the courses_students table.

1 Comment

Thanks :) and what about the id => false statement in the create_table line?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.