Topic: Creating nested hash from nested active record results

  I'm trying to find a very abstract and "one size fits all" for converting nested active record results to nested hashes.   It's easy, to do one level deep as such:

results_to_hash = Hash[{ |c| [, c.title]}]

But, when I try to add another collection to the mix, it completely borks and the results_to_hash only returns an empty hash IE:

results_to_hash = Hash[{ |c| [, c.title, c.categories]}]

Ultimately, I'd like it to be smart enough to detect if a model object contains a collection (IE: object.class.reflect_on_all_associations), and automatically convert those to hashes.

Any ideas?


Last edited by clem_c_rock (2013-05-22 12:52:37)