Forum: Ruby on Rails Create a SelfJoin has_many

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
444779db9beb126e6e758752357beadb?d=identicon&s=25 Matheus S. (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
This topic is locked and can not be replied to.