take-five / activerecord-hierarchical_query

Simple DSL for creating recursive queries with ActiveRecord
MIT License
119 stars 24 forks source link

to_hash #5

Closed mikeni closed 8 years ago

mikeni commented 8 years ago

is there anyway to convert results into nested hashes representing a tree of results?

take-five commented 8 years ago

Hello

It can be implemented for trees, but that's not what library has been built for. The idea is that you can select arbitrary hierarchical data in a single query and receive flat result set.

If you want to build nested hash using that result set, than you somehow need to know which node is "parent" and which is "child", and I find a bit hard to find out for general case.

But you can quite easily implement this feature yourself using this code as an ispiration: https://github.com/take-five/acts_as_ordered_tree/blob/master/lib/acts_as_ordered_tree/iterators/arranger.rb

mikeni commented 8 years ago

Thank you for the gem and the reply.