On Monday, July 3, 2017 at 6:30:04 PM UTC-7, Aryk Grosz wrote:
>
> Hi Jeremy, I think I might PR that. Would love to contribute.
>
> In addition to this, I noticed in your paged_each code you do not call 
> "all" after applying the limit and offset. Wouldn't this bypass calling 
> #eager and then paged_each?
>
> Any reason for this? How do you recommend I get the benefits of eager with 
> paged_each?
>

You can't really eager load without getting all records up front..  Having 
paged_each do eager loading would result in N/S queries per association, 
where N is the number of rows and S the number for rows per page.  It could 
partially work for #eager, but definitely could not work for #eager_graph.

If you are iterating over the entire dataset, you can do:

id_map = AssociatedClass.as_hash
MainClass.paged_each do |row|
  row.associations[:association_name] = id_map[row[:key_column]] # 
many_to_one
end

or similar things for other association types.

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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to