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

Cannot use Sequel pagination #311

Closed
snacks02 opened this issue Mar 22, 2023 · 14 comments
Closed

Cannot use Sequel pagination #311

snacks02 opened this issue Mar 22, 2023 · 14 comments

Comments

@snacks02
Copy link
Contributor

snacks02 commented Mar 22, 2023

Sequel has a built-in extension for pagination that doesn't seem to work with Datagrid.

# all_sites_grid.rb
class AllSitesGrid < BaseGrid
  scope do
    Site
  end
end

# sites_controller.rb
grid = AllSitesGrid.new do
  Site.dataset.paginate(1, 25)
end
SitesControllerTest#test_#all_sites_table_works:
Sequel::Error: You cannot paginate a dataset that already has a limit
    app/controllers/sites_controller.rb:269:in `all_sites_table'
    test/controllers/sites_controller_test.rb:248:in `block in <class:SitesControllerTest>'
    test/test_helper.rb:23:in `block in run'
    test/test_helper.rb:23:in `run'
@snacks02
Copy link
Contributor Author

The workaround that I came up with:

# all_sites_grid.rb
class AllSitesGrid < BaseGrid
  scope do
    []
  end
end

# sites_controller.rb
grid = AllSitesGrid.new do
  Site.dataset.paginate(1, 25).to_a
end

@bogdan
Copy link
Owner

bogdan commented Mar 22, 2023

Can you open the console and run Site.dataset.paginate(1, 25)? If it generates an exception for you, there is nothing datagrid can do about it and you are using sequel incorrectly. You may search for support in sequel forums.

Anyway, your grid imitation code looks incorrect. It should be:

grid = AllSitesGrid.new do |scope|
  scope.paginate(1, 25)
end

@snacks02
Copy link
Contributor Author

It works in the console:

irb(main):001:0> Site.dataset.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">

Not sure what you mean by grid imitation, but this is the error with your suggestion:

NoMethodError: undefined method `paginate' for Site:Class

@bogdan
Copy link
Owner

bogdan commented Mar 22, 2023

Try the following:

# all_sites_grid.rb
class AllSitesGrid < BaseGrid
  scope do
    Site.dataset
  end
end

# sites_controller.rb
grid = AllSitesGrid.new do |s|
  s.paginate(1, 25)
end

@snacks02
Copy link
Contributor Author

The same error even on master:

Sequel::Error: You cannot paginate a dataset that already has a limit

@bogdan
Copy link
Owner

bogdan commented Mar 23, 2023

Try the following in console:

AllSitesGrid.new.scope.paginate(1,25)
AllSitesGrid.new.assets.paginate(1,25)

What is the result?

@snacks02
Copy link
Contributor Author

irb(main):001:0> AllSitesGrid.new.scope.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">
irb(main):002:0> AllSitesGrid.new.assets.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">

@bogdan
Copy link
Owner

bogdan commented Mar 23, 2023

Try the following too:

AllSitesGrid.new{|s| s.paginate(1,25)}.assets.to_a

Also, let me know, which specific line is showing up in the backtrace with the error.

@snacks02
Copy link
Contributor Author

Sorry, but can't you try it? It should be easy to reproduce.

@bogdan
Copy link
Owner

bogdan commented Mar 23, 2023

I did. It is not reproducing.

class PaginationTest

@snacks02
Copy link
Contributor Author

The test fails though.

Also, doing scope.limit(10) results in the same error.

@bogdan
Copy link
Owner

bogdan commented Mar 23, 2023

I have no idea how limit appears in your code. You need to provide a full controller action, view, grid and model source code.

@snacks02
Copy link
Contributor Author

See #312.

bogdan pushed a commit that referenced this issue Mar 23, 2023
@snacks02
Copy link
Contributor Author

Thanks!

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

No branches or pull requests

2 participants