I've been coming back to a problem I haven't solved on my own. I've got a shipments
table with two columns for addresses
, namely to_address_id
and from_address_id
.
After looking at a related question (Same Model for Two belongs_to Associations migration), I am still confused. Here is my work so far. I haven't run the migration. I'm trying to resolve this in my mind before getting worked up about it and waste an hour or two. I really thank you for your help.
class AddAddressFromAndAddressToToAddress < ActiveRecord::Migration[6.0]
def change
add_reference :address, :address_from, null: false
add_reference :address, :address_to, null: false
add_foreign_key :address, :shipments, column: :to_address_id
add_foreign_key :address, :shipments, column: :from_address_id
end
en