[Bug] default_pagination_type is an unknown option in derived schemas
m1dnight opened this issue · 5 comments
Summary
Hi,
I'm using Flop to have cursor-based navigation on some webpages. When I want to force the navigation method to be cursor based by setting the option default_pagination_type
it works as expected:
query
|> Flop.validate_and_run(params,
for: Client,
default_pagination_type: :first,
pagination_types: [:first, :last]
)
Since I'm using this type of pagination in multiple places, I tried setting that option in the derived schema:
@derive {
Flop.Schema,
filterable: [:searchable],
sortable: [:id, :is_active],
default_order: %{
order_by: [:is_active, :id],
order_directions: [:desc, :asc]
},
pagination_types: [:first, :last],
default_pagination_type: :first,
join_fields: [
user_firstname: [binding: :users, field: :firstname],
user_lastname: [binding: :users, field: :lastname],
client_group_name: [binding: :client_group, field: :name],
user_full_name: [
binding: :computed,
field: :full_name
],
user_name_full: [
binding: :computed,
field: :name_full
]
],
compound_fields: [
searchable: [
:name,
:vat,
:user_firstname,
:user_lastname,
:client_group_name,
:user_full_name,
:user_name_full,
:commercial_name_nl_BE,
:commercial_name_fr_BE,
:commercial_name_de_DE,
:commercial_name_en_GB,
:entity_name
]
]
}
The option default_pagination_type: :first,
in the derived schema throws the following error:
== Compilation error in file lib/snipped/clients/repos/client.ex ==
** (ArgumentError) unknown option(s): [:default_pagination_type]
(flop 0.20.0) lib/flop/schema.ex:787: Flop.Schema.Any.validate_no_unknown_options!/1
(flop 0.20.0) lib/flop/schema.ex:702: Flop.Schema.Any.validate_options!/2
(flop 0.20.0) expanding macro: Flop.Schema.Any.__deriving__/3
lib/snipped/clients/repos/client.ex:146: Snipped.Client (module)
Steps to reproduce
I have built a minimal working example using the Pet example in the docs that shows the error.
The repo can be found here: https://github.com/m1dnight/flop_bug
Expected behaviour
The default pagination method should be cursor-based, and be chosen without passing the options in each validate_and_run
call.
So instead of
|> Flop.validate_and_run(params,
for: Client,
default_pagination_type: :first,
pagination_types: [:first, :last]
)
i want to be able to do
|> Flop.validate_and_run(params, for: Client )
Actual behaviour
An error is thrown.
Elixir/Erlang version
IEx 1.14.4 (compiled with Erlang/OTP 25)
Flop and Ecto versions
- ecto 3.10.1 (Hex package) (mix)
- ecto_sql 3.10.1 (Hex package) (mix)
locked at 3.10.1 (ecto_sql) f6a25bdb - flop 0.20.0 (Hex package) (mix)
locked at 0.20.0 (flop) 666696c9
Additional context
Thanks for a great lib <3
I'm happy to help where I can (if it's a bug?), but I'm unsure where to get started.
I think it was intentionally implemented this way, but we can change it. PR welcome, if you want to take a stab.
Ah, but the docs mentioned it in an example here: https://hexdocs.pm/flop/schema.html#basics so that threw me off.
I'm pressed for time right now, but I'll give it a shot later today!
Looks like there was too much time between implementation and writing the cheat sheet 😅
Hi, sorry to only get back to this at this time. Just wanted to let you know I really appreciate you taking the time to fix this. Thanks!