Check out example codes for "rails self relation". It will help you in understanding the concepts better.

Code Example 1

class MyModel < ActiveRecord::Base
  belongs_to :parent, :class_name => 'MyModel'
  has_many :children, :class_name => 'MyModel', :foreign_key => 'parent_id'
end

Learn ReactJs, React Native from akashmittal.com