Pagination does not work on models

11 views
Skip to first unread message

Алексей Мацкевич

unread,
Aug 22, 2021, 11:47:02 AMAug 22
to sequel-talk
I use Sequel version 5.44
```ruby
# foo_model.rb
class FooModel < Sequel::Model
  plugin :json_serializer
  plugin :timestamps, update_on_create: true
end
# console
> Sequel.extension :pagination
[
    [0] :pagination
]

> FooModel.paginate(1,2)
NoMethodError: undefined method `paginate' for FooModel:Class
```
I was struggling with this for hours studying the documentation but was not successful, what could I have done wrong?

Marcelo Pereira

unread,
Aug 23, 2021, 3:13:52 AMAug 23
to seque...@googlegroups.com
To make it work, you need to:
- Enable the extension prior to defining the FooModel class
- Run the paginate method on the model dataset with FooModel.dataset.paginate(1,2)

I'm not sure if there's a reason why the model doesn't proxy the paginate method to its underlying dataset.

Best

--
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 sequel-talk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/bcb3ae77-8b20-4817-aa03-1162b6e6ed13n%40googlegroups.com.

Алексей Мацкевич

unread,
Aug 23, 2021, 6:31:43 AMAug 23
to sequel-talk
I've tried loading the extension before defining models, it doesn't work.
And I tried calling dataset on the model and pagination on it - that doesn't work either.
The only thing that works is pagination directly on the db schema - 
```ruby
DB[:foo_models].paginate(1,2)
```
понедельник, 23 августа 2021 г. в 10:13:52 UTC+3, Marcelo:

Jeremy Evans

unread,
Aug 23, 2021, 10:31:28 AMAug 23
to seque...@googlegroups.com
On Mon, Aug 23, 2021 at 12:13 AM Marcelo Pereira <marcelovit...@gmail.com> wrote:
To make it work, you need to:
- Enable the extension prior to defining the FooModel class
- Run the paginate method on the model dataset with FooModel.dataset.paginate(1,2)

I'm not sure if there's a reason why the model doesn't proxy the paginate method to its underlying dataset.

pagination is a dataset extension, not a model plugin, so it won't affect model classes, only datasets.  You can add your own paginate class method that calls the paginate method on the model's dataset.

Thanks,
Jeremy

Алексей Мацкевич

unread,
Aug 23, 2021, 10:46:19 AMAug 23
to sequel-talk
Thanks

понедельник, 23 августа 2021 г. в 17:31:28 UTC+3, Jeremy Evans:
Reply all
Reply to author
Forward
0 new messages