t.belongs_to in migration
The t.belongs_to :category
is just a special helper method of rails passing in the association.
If you look in the source code belongs_to
is actually an alias of references
Yes, it's an alias; It can also be written t.references category
.
$ 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