Forum: Ruby on Rails Create a SelfJoin has_many

Ea9b0b89db6b5fef846c58befa96d83b?d=identicon&s=25 Matheus Silva (matheusao)
on 2016-12-21 18:19
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

    add_foreign_key :feedstocks, :feedstocks, column:
:primary_feedstock_id, primary_key: :id

One feedstock has one primary_feedstock and one primary_feedstock has
many feedstocks
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.