On Monday, August 19, 2013 4:43:50 AM UTC-7, Adam Gamble wrote: > > I'm writing a REST interface in Sinatra where I have two models, a * > PhotoSet* and a *Photo, *where *Photo* has a *many_to_one *relationship > with *PhotoSet*. > > A *Photo* has EXIF data attached including `Float :lat` and `Float :lng` > – at some point I need to collect each *lat/ lng *(ordered by the time > the photo was taken) to get a poly-line, so from the perspective of the > REST, contained in the JSON reply to `/set/:id`. > > For easy access I wondered if I can store this in the PhotoSet as `String > :polyline`, with a hook in the Model? Or I am better off just querying the > *Photo*'s on request (i.e. `Photo.where(:set_id => id)` within the route > logic)... thought this could be potentially expensive... :/ >
I would start out by querying the Photo's on request: photoset.photos_dataset.order(:taken_at).select_map([:lat, :lng]) If that ends up being a bottleneck in your application, then you should consider denormalizing. But doing so in advance is probably premature optimization. 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/groups/opt_out.
