method
references
v2.2.1 -
Show latest stable
-
2 notes -
Class: ActiveRecord::ConnectionAdapters::Table
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (5)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-4)
- 4.1.8 (0)
- 4.2.1 (31)
- 4.2.7 (-38)
- 4.2.9 (0)
- 5.0.0.1 (4)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
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)
Register or
log in
to add new notes.
avit -
August 22, 2008
4 thanks
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
apsoto -
April 23, 2015
0 thanks
add index directly
You can add an index now directly on the foreign_key :
t.references(:user, index: true)