I'm looking for an easy way to apply eager loading of any nested 
association for a single record, ideally performed at the same time when 
the record is retrieved. Currently I can achieve this with:

  artist = Artist
    .eager(albums: :tracks)
    .where(id: artist_id)
    .limit(1)
    .all
    .first

However, `Artist.where(id: id).limit(1).all.first` is a lot longer than 
just `Artist[id]`. Is there by any chance a shorter way to do it? I'm also 
fine with eager loading after the record has been retrieved.

My goal is to improve SRP in my app; I want to localize where records are 
retrieved, so that when I pass the model instance to a class, that this 
class doesn't have to worry about eager loading anymore (one example is a 
presenter class which builds a JSON representation which includes fields of 
associated records).

Kind regards,
Janko

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

Reply via email to