In Self join association one model has relation with itself. For example one user table can have list of all coach and player. One coach can train many players. We will represent the association as:
class User < ActiveRecord::Base
has_many :players, :class_name => "User", :foreign_key => "coach_id"
belongs_to :coach, :class_name => "User"
end
With the above self join association we can retrieve all the players under a coach as @coach.players and coach of a player as @player.coach.
0 Comment(s)