t.belongs_to in migration

前端 未结 6 1309
攒了一身酷
攒了一身酷 2020-12-25 10:31

I was using Ryan Bates\'s source code for railscasts #141 in order to create a simple shopping cart. In one of the migrations, he lists

class CreateProducts         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-25 11:13

    $ rails g migration AddUserRefToProducts user:references 
    

    this generates:

    class AddUserRefToProducts < ActiveRecord::Migration
      def change
        add_reference :products, :user, index: true
      end
    end
    

    http://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration

提交回复
热议问题