0

let's imagine this situation.I have a article model and a sort model,and they have a one-to-many association.

the article migration is :

create_table :articles do |t|
  t.string :title      
  t.string :content
  t.belongs_to :sort

  t.timestamps
end

the sort migration is :

create_table :sorts do |t|
    t.string :title  

    t.timestamps
end

so the article will be added a filed named sort_id.

now,I want to add an index on the filed sort_id in table articles.

whether I can realize as follow:

   add_index :articles, :sort, :unique => true 

or

  add_index :articles, :sort_id, :unique => true 
4

1 回答 1

1
add_index :articles, :sort_id, :unique => true 
于 2013-09-26T09:50:20.010 回答