开发者

ActiveRecord default indexes

开发者 https://www.devze.com 2023-02-03 18:27 出处:网络
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\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消