duffelhq / paginator

Cursor-based pagination for Elixir Ecto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query with a fragment seems to return the after and before keys swapped.

alvesl opened this issue · comments

Example query:

   Model
    |> order_by([o], desc: fragment("date(?)", o.inserted_at))
    |> group_by([o], fragment("date(?)", o.inserted_at))
    |> select([o], %{fragment("date(?)", o.inserted_at) => sum(o.amount)})
    |> Repo.paginate(Keyword.merge(opts, sort_direction: :desc, cursor_fields: [:inserted_at]))

Returns properly and seems to paginate correctly if I pass in the before Key. For some reason the after key returns the same element. Any idea what is going on?

ping

I think you need a window function to achieve paginating after grouping. See this question on Stackoverflow: https://stackoverflow.com/questions/54329389/postgresql-paginate-by-rows-group

So I do not think this is a bug in the library.