method
references
v3.0.9 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::Table
references(*args)public
Adds a reference. Optionally adds a type column. references and belongs_to are acceptable.
Examples
t.references(:goat) t.references(:goat, :polymorphic => true) t.belongs_to(:goat)
2Notes
Doesn't add an index
Typically you will want to have an index on foreign keys but this method doesn't assume that. Outside of the create_table block you should follow this with add_index :
add_index :table_name, :goat_id
# and, if polymorphic:
add_index :table_name, :goat_type
add index directly
You can add an index now directly on the foreign_key :
t.references(:user, index: true)