File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ defmodule Rummage.Ecto.Hooks.Sort do
3838
3939 iex> alias Rummage.Ecto.Hooks.Sort
4040 iex> import Ecto.Query
41- iex> rummage = %{"sort" => [ "field_1.asc"] }
42- %{"sort" => [ "field_1.asc"] }
41+ iex> rummage = %{"sort" => "field_1.asc"}
42+ %{"sort" => "field_1.asc"}
4343 iex> query = from u in "parents"
4444 #Ecto.Query<from p in "parents">
4545 iex> Sort.run(query, rummage)
@@ -55,15 +55,12 @@ defmodule Rummage.Ecto.Hooks.Sort do
5555 end
5656
5757 defp handle_sort ( query , sort_params ) do
58- order_params =
59- Enum . reduce ( sort_params , [ ] , fn ( unparsed_field , order_params ) ->
60- cond do
61- Regex . match? ( ~r/ \w .asc+$/ , unparsed_field ) or
62- Regex . match? ( ~r/ \w .desc+$/ , unparsed_field ) ->
63- add_order_params ( order_params , unparsed_field )
64- true -> order_params
65- end
66- end )
58+ order_params = cond do
59+ Regex . match? ( ~r/ \w .asc+$/ , sort_params ) or
60+ Regex . match? ( ~r/ \w .desc+$/ , sort_params ) ->
61+ add_order_params ( [ ] , sort_params )
62+ true -> [ ]
63+ end
6764
6865 query |> order_by ( ^ order_params )
6966 end
You can’t perform that action at this time.
0 commit comments