On Monday, June 22, 2020 at 5:22:56 AM UTC-7, shreko wrote:
>
> For classic example of Eager loading fom docs:
>
> Artist.one_to_many :albums
> Album.one_to_many :tracks
> Tracks.many_to_one :lyric
>
>
> artists = Artist.eager(albums: {tracks: :lyric})
>
>
> In order to get full data structure json, is there a way to write 
> json_serializer_opts a bit more concise than the following 
>
> artists.each do |artist| 
>   artist.json_serializer_opts(include: :albums)
>         
>   artist.albums.each do |album|
>     album.json_serializer_opts(include: :tracks)
>          
>     album.tracks.each do |track|
>       track.json_serializer_opts(include: :lyric)
>     end            
>        
>   end
> end
>

I think the following should work:

  Artist.eager(albums: {tracks: 
:lyric}).json_serializer_opts(:include=>{:albums=>{:include=>{:tracks=>{:include=>:lyric}}}})

If not, please let me know.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/ed8fc534-4106-4739-a806-fc43cf35640ao%40googlegroups.com.

Reply via email to