1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib/rails/generators
Ernst Rullmann 138c1db83e Added references option to join tables
Fixes issue #22960
When creating join tables with the command

    rails g migration CreateJoinTableShowroomUser showroom:references user:references

The migration will use references to create the joins and output:

     class CreateJoinTableShowroomUser < ActiveRecord::Migration
       def change
         create_join_table :showrooms, :users do |t|
           t.references :showroom, index: true, foreign_key: true
           t.references :user, index: true, foreign_key: true
         end
       end
     end

This allows for proper refrences with indexes and foreign keys to be easily used when
adding join tables. Without `:refrences` the normal output is generated:

    class CreateJoinTableShowroomUser < ActiveRecord::Migration[5.0]
      def change
        create_join_table :showrooms, :users do |t|
          # t.index [:showroom_id, :user_id]
          # t.index [:user_id, :showroom_id]
        end
      end
    end
2016-01-31 23:20:07 -05:00
..
active_record Added references option to join tables 2016-01-31 23:20:07 -05:00
active_record.rb Use thor class_option to make the primary_key_type option work 2015-10-23 21:34:07 -02:00