Hi Jeremy,

When I have an already instantiated Sequel model, is it possible to apply 
cascaded eager loaded associations? For example, if I have

class User < Sequel::Model
  one_to_many :quizzes
end

class Quiz < Sequel::Model
  one_to_many :questions
end

class Question < Sequel::Model
end

Is it possible to make it that `user.quizzes.map(&:questions)` executes 
only one query for questions (that questions are eager loaded). I need this 
because when I'm returning a single record, any previous eager loading are 
canceled. That is, the following

User.eager(:quizzes => :questions).first.quizzes.map(&:questions)

Will separately fetch questions for each quiz, even though I eager loaded 
them. The reason why I can't just call 
`user.quizzes_dataset.eager(:questions)` is because when I'm serializing 
that user for a JSON response, the serializer will automatically serialize 
the `user.quizzes.questions` association, by calling the association 
methods directly. So, the serializer would have to somehow know not to call 
`user.quizzes`, but `user.quizzes_dataset.eager(:questions).all`, which I 
don't know how to implement without some nasty special case.

So, I would like to somehow on the instance level cause the method 
`user.quizzes` to automatically return quizzes with eager loaded questions.

-- 
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.

Reply via email to