On Monday, April 28, 2014 10:32:15 PM UTC-7, Ross Attrill wrote: > > I have a tree of associated Sequel::Model objects that I wish to convert > to simple arrays and hashes with the objective of serializing to JSON. > > I am not quite sure what the best way of doing this. > > At the moment I am calling the auto generated getter method of child > associations then converting the results to arrays or hashes etc manually > and pushing this all together into into a data structure. > > I am wondering if there is an approach built into Sequel that would make > this easier. > > I can see that we can declare associations as eager loading. This would > fix one issue for me as I would no longer need to manually call the child > association getter. > > But I am wondering if there is some simple approach that I can use at > runtime that would automatically expand down a specified number of child > levels. > > Similarly, once loaded, is there a simple way that I can convert all of > the Sequel::Model objects in a tree hierarchy to simple arrays and hashes, > ready for serialization? > > Thank you very much for help with this. >
The json_serializer plugin should handle this use case, though it converts directly to json, it doesn't just return simple hashes and arrays. For very complex cases, you may want to consider rabl or a similar json templating library. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
