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

Support filtering :id type fields #429

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/torch/pagination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Torch.Pagination do
defp build_filter_config(model, schema_attrs) do
schema_attrs
|> Enum.reduce(
Map.from_keys(~w(date number text boolean)a, []),
Map.from_keys(~w(date number text boolean id)a, []),
&collect_attributes_by_type(&1, model.__schema__(:type, &1), &2)
)
|> Enum.reduce([], &build_filtrex_configs/2)
Expand All @@ -173,7 +173,7 @@ defmodule Torch.Pagination do
do: collection

defp collect_attributes_by_type(attr, attr_type, collection)
when attr_type in [:integer, :number] do
when attr_type in [:integer, :number, :id] do
Map.update(collection, :number, [attr], fn curr_value -> [attr | curr_value] end)
end

Expand Down
6 changes: 3 additions & 3 deletions test/torch/pagination_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule PaginationTest do
assert ~w(body title) == Enum.sort(attr_keys)

:number ->
assert ~w(view_count) == Enum.sort(attr_keys)
assert ~w(id view_count) == Enum.sort(attr_keys)

:boolean ->
assert ~w(archived) == Enum.sort(attr_keys)
Expand All @@ -105,7 +105,7 @@ defmodule PaginationTest do
assert ~w(body title) == Enum.sort(attr_keys)

:number ->
assert [] == attr_keys
assert ~w(id) == attr_keys

:boolean ->
assert [] == attr_keys
Expand All @@ -122,7 +122,7 @@ defmodule PaginationTest do
assert [] == attr_keys

:number ->
assert [] == attr_keys
assert ~w(id) == attr_keys

:boolean ->
assert [] == attr_keys
Expand Down
Loading