self association rails code example
Example 1: rails self relation
class MyModel < ActiveRecord::Base
belongs_to :parent, :class_name => 'MyModel'
has_many :children, :class_name => 'MyModel', :foreign_key => 'parent_id'
end
Example 2: self referencing association in ruby on rails
has_many :users, class_name: 'User'
belongs_to :manager, class_name: 'User', optional: true