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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies 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:

 
 
subject: Creating nested hash from nested active record results
 
Similar Threads
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?
bigger value in function MAX(x,y)
Problem javax.persistence.NoResultException: No entity found for query