I have a problem I've been banging my head against for awhile and I can't seem to figure out a good approach. Imagine an application that collects some historical data over time for a related model:
class Albums < Sequel::Model one_to_many :daily_sales_figures, :order => :date end class DailySalesFigure < Sequel::Model # Includes date column and numerous statistics such as units sold, average price, etc. many_to_one :album end The user wants to see a list of albums, each with a sparkline showing a daily sales figure for that album. For the sparkline, they want to be able to choose both the time period (last quarter, YTD, etc.) and the statistic (units sold, average price, etc.). The obvious way to implement this is as a query over albums, eager loading :daily_sales_figures. Here's the nut of the problem: suppose sales figures go back for decades, and include hundreds of statistics, so that for performance reasons, it would be highly advantageous to be able to filter the eager loaded dataset to just the chosen time period, and select only the single column needed for the sparkline. There doesn't seem to be an easy way to do this with Sequel -- #eager uses the association options (e.g. :conditions, :select) that were fixed at association definition time, whereas the user's choices change from request to request. Right now I'm doing some crazy stuff involving dynamically creating new association reflections at query time, but it's really really ugly. I've also considered constructing the join and updating association caches manually -- this doesn't seem ideal either, as it essentially means a bespoke reimplementation of #eager at every place this needs to be done (and I have multiple analogous models). Is there some other way to get some dynamism with eager loading? -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
