method
add_reference

v4.0.2 -
Show latest stable
-
1 note -
Class: ActiveRecord::ConnectionAdapters::SchemaStatements
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (13)
- 4.2.7 (15)
- 4.2.9 (0)
- 5.0.0.1 (38)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (9)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-3)
- 7.1.3.4 (0)
- What's this?
add_reference(table_name, ref_name, options = {})
public
Adds a reference. Optionally adds a type column, if :polymorphic option is provided. add_reference and add_belongs_to are acceptable.
Create a user_id column
add_reference(:products, :user)
Create a supplier_id and supplier_type columns
add_belongs_to(:products, :supplier, polymorphic: true)
Create a supplier_id, supplier_type columns and appropriate index
add_reference(:products, :supplier, polymorphic: true, index: true)
Register or
log in
to add new notes.
cmbankester -
June 7, 2016

0 thanks
foreign_key option
It is also possible to specify that add_foreign_key should be added to the schema:
add_reference(:products, :supplier, foreign_key: true)