wood burning stoves 2.0*
The moose likes Ruby and the fly likes Creating nested hash from nested active record results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Creating nested hash from nested active record results" Watch "Creating nested hash from nested active record results" New topic
Author

Creating nested hash from nested active record results

Eric Hermann
Greenhorn

Joined: May 07, 2013
Posts: 6


Hello,
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:



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:



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?

Thanks,
Eric
Eric Hermann
Greenhorn

Joined: May 07, 2013
Posts: 6
Just an FIY - this was my solution:

 
Don't get me started about those stupid light bulbs.
 
subject: Creating nested hash from nested active record results