E
E
eldar_web2015-09-01 15:18:43
Ruby on Rails
eldar_web, 2015-09-01 15:18:43

How to sort out data from a database in Rails where the nesting level is unknown ???

Take, for example, the assistant manager. That is, each chief has his assistants, and in turn these assistants have their assistants, and so on.
For example, they have such a relationship Boss.id = Аssistant.boss_id (has_many, belongs_to - many to one).
So there is a boss with id = 5. And I need to take all the id-shniks of my assistants, including their assistants, and so on until the end.
And how to implement it if I don't know the levels???

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Bobykin, 2015-09-01
@Qelphybox

the best solution would be to include the gem https://github.com/collectiveidea/awesome_nested_set

T
thepry, 2015-09-01
@thepry

If speed is not important, then simple recursion.

P
panikerik, 2015-09-10
@panikerik

habrahabr.ru/post/130371
will help a lot if you use pg))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question