aspose file tools*
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
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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating nested hash from nested active record results