Awesome, I didn't know about this plugin, thanks! Btw, that plugin also makes eager loading when fetching a single record work, so it's another solution for my other use case I had.
Artist .eager(albums: :tracks) .with_pk(artist_id) Thanks for the tip! Kind regards, Janko On 8 Feb 2019, 16:28 +0100, Jeremy Evans <[email protected]>, wrote: > On Friday, February 8, 2019 at 7:13:11 AM UTC-8, Janko Marohnić wrote: > > Hello Jeremy, > > > > When specifying that a dataset should eager load certain associations, we > > don't always remember to call #all when retrieving records. We often > > accidentally call #each or #map or `#to_a`, in which case nothing is eager > > loaded. Given that we always want to call #all if we specified eager > > loading, I'm looking for a way how to either prevent ourselves from calling > > #each/#map/#to_a when we specified `.eager`, or to modify #each to > > automatically call #all. > > > > I tried overriding #each, but since #all calls #each internally, it's a bit > > tricky because I have no way of knowing whether #each was called by #all or > > directly. Do you by any chance have any ideas how to achieve this? > > The eager_each plugin will internally call #all if you call #each on an eager > loaded dataset. > > Thanks, > Jeremy > -- > You received this message because you are subscribed to a topic in the Google > Groups "sequel-talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sequel-talk/lfVLcmrO9XY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sequel-talk. > For more options, visit https://groups.google.com/d/optout. -- 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 https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
