Forum: Ruby on Rails Create a SelfJoin has_many

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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

      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
This topic is locked and can not be replied to.