ActiveRecord default indexes
Does Rails (v3) create an index on the id column by default, or do I have to add the line
"add_index :table, :id, :unique => 开发者_运维问答true"
into the migration file?
ActiveRecord requires that every table has a primary key. It is called "id" by default. You don't need to add it in your migrations.
If you are creating a reference to another table, you will need to create the reference columns somewhat manually. You can either do t.integer :user_id
or (my preference) t.belongs_to :user
. The latter is slower, though, because Rails will invoke ActiveRecord to determine what to call the user reference column.
精彩评论