add_reference

add_reference(table_name, ref_name, options = {})
Instance Public methods

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)

add_belongs_to

doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.