Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to pager so Sequel's eager can be used with pagination #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nibble
Copy link

@nibble nibble commented Jan 21, 2014

Sequel can preload all matching associations by using the eager method. It will first load the dataset with the given query, and then it will query the database once for each one of the specified associations. For this to work, the query executing method has to be all, not the usual each, but it can still have pagination parameters as part of the query.

This change provides an all method to the pager, that is propagated to Sequel's dataset. It also includes ArrayPager#all, that returns the array range, to ensure proper compatibility with plain arrays.

Here is an usage example. It will generate 2 SQL queries, instead of 1 + N:

# controller
@artists = paginate(Artist.eager(:albums))
<!-- view -->
<?r @artists.all.each do |artist| ?>
  #{artist.name}
  <?r artist.albums.each do |album| ?>
    #{album.title}
  <?r end ?>
<?r end ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant