Ruby on Rails - create a join table in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
To create a join table between students and courses
Command for run
$ rails g migration CreateJoinTableStudentCourse student course
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
This will generate the below migration:
class CreateJoinTableStudentCourse < ActiveRecord::Migration[5.0]
def change
create_join_table :students, :courses do |t|
# t.index [:student_id, :course_id]
# t.index [:course_id, :student_id]
end
end
end