I have a PhotoSet, which has a one_to_many relationship with Photos. Each 
Photo has a latitude (lat) and longitude (lng) associated with it, along 
with (DateTime) date_taken.

Using Sinatra as a REST service, my desired output would be:

[{
  title: set1,
  photos: [[lat1, lng1],[lat2, lng2]]  # or even better, photos renamed to 
'route'
}]

...with each [lat, lng] ordered by date_taken...

Totally lost as to how to achieve this, I can get this far using Sequel's 
JSON Serializer plugin:


  PhotoSet.where(:parent_id => nil)                                         
                                                                            
               
    .to_json(:include => {                                                 
                                                                            
                
               :photos => {                                                 
                                                                            
               
                 :only => [:lat, :lng],                                     
                                                                            
               
               },                                                           
                                                                            
               
             }) 

which returns:

[
    {
        "id": 1,
        "title": "",
        "date_created": "2013-09-14T15:53:16+00:00",
        "photos": [
            {
                "lat": 52.95386867000556,
                "lng": -2.2866811700101857
            }
        ]
    }
]

Thanks,

Adam

-- 
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/groups/opt_out.

Reply via email to