ActiveRecord default metrics

Does Rails (v3) create an index in the id column by default or do I need to add a row

"add_index :table, :id, :unique => true"

to the migration file?

+4
source share
1 answer

ActiveRecord requires that each table has a primary key. By default it is called "id". You do not need to add it to your migrations.

If you create a link to another table, you will need to create the referenced columns somewhat manually. You can either do t.integer :user_id , or (my preference) t.belongs_to :user . The latter is slower because Rails will call ActiveRecord to determine how to invoke the user link column.

+4
source

Source: https://habr.com/ru/post/1335331/


All Articles