Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
 
Similar Threads
Problem javax.persistence.NoResultException: No entity found for query
bigger value in function MAX(x,y)
Need to retrieve only perticular attributes from table
SQL Join for two different columns
Can Windows 2008 server block specific user from running a javascript?