Create a SelfJoin has_many


#1

I am trying to do a Self-join and I generate this migration to make a
correct primary, I’m not sure if this is really right. There is some
problem here?

class CreateFeedstocks < ActiveRecord::Migration[5.0]
def change
create_table :feedstocks do |t|
t.string :code
t.float :measure_one
t.float :measure_two
t.float :measure_three
t.string :description
t.integer :primary_feedstock_id, index: true

  t.timestamps
end
add_foreign_key :feedstocks, :feedstocks, column:

:primary_feedstock_id, primary_key: :id
end
end

One feedstock has one primary_feedstock and one primary_feedstock has
many feedstocks