To answer the question "What would be the migration generation team to establish this relationship?" (the meaning of how you add hyphenation for existing models with relationships such as User has_many Tasks and Task belongs_to User )
The easiest way to remember:
>rails g migration AddUserToTask user:belongs_to
or
>rails g migration AddUserToTask user:references
:belongs_to is just an alias :references , so either do the same.
By doing this, the command will extract the table name from the migration name, configure the change method, which will add a column for the relationship, and configure it for indexing:
class AddUserToTask < ActiveRecord::Migration def change add_reference :tasks, :user, index: true end end
After creating this, you:
>rake db:migrate
Finally, you still have to add the usual relationships to your models as indicated in the other answers, but I think this is the correct answer to your question.
chad_ Sep 22 '14 at 19:32 2014-09-22 19:32
source share