That solves the problem perfectly! On Wednesday, May 13, 2015 at 3:45:29 AM UTC+2, Jeremy Evans wrote: > > On Tuesday, May 12, 2015 at 10:48:15 AM UTC-7, Janko Marohnić wrote: >> >> Hi Jeremy, >> >> In my JSON API I'm allowing clients to pass in associations which they >> want to use for a retrieved object: >> >> GET /users?include=quizzes.questions,posts >> >> For that to be performant, I would like to eager load the requested >> associations. I was first thinking of parsing that "include" query, and >> eager loading the specified associations. It's fairly easy to implement, >> but I came to a wall when I need to eager load on a single object. The >> reason why I can't eager load on the dataset before fetching a single >> object is because it needs to happen dynamically during the serialization >> process; I give the serializer the object to serialize, which can be a >> dataset or a single instance, and then the serializer checks for the >> "include" query and calls eager loading. >> >> What I was thinking, can I just have all my associations eager loaded by >> default? This seems to solve the case perfectly, because the query will >> happen only when you request the associations, meaning only associations >> that you are using will be fetched. So then I never need to think about >> eager loading, right? :) >> >> Of course, that's my naive opinion, but I'm curious are there any >> downsides of this approach? Is it currently possible to tell Sequel to >> eager load all associations associations for a model when instantiating its >> dataset? >> > > You may want to look into the tactical_eager_loading plugin, which can do > automatic eager loading for associations (without specifying them in > advance via Dataset#eager), assuming that the object on which you are > calling the association method was retrieved via Dataset#all. > > 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.
