I have a table like following

well,here in this table every user has a parent user,then if we select a user then its id ,children ids and children childrens ids should return as array.I need a query to get this values in rails with out using any gem.Thanx for your help:->
When call either Superiors(parents) or Subordinates(childrends) it will gives required result
Ex:- [2,4,6,8]
If you want to get either children->childrends or parent->parents just do iterate call function either superior or subordinates until get the nil or [] array .