duffelhq / paginator

Cursor-based pagination for Elixir Ecto
MIT License
750 stars 90 forks source link

cursor fields can't find field inside select ordered by fragment #194

Open allanegidio opened 9 months ago

allanegidio commented 9 months ago

Hey guys.

I've been having some issues executing queries with select bidings and ordering by these bidings using fragments. If I have some query that is using :select bidings for example and ordered by it using fragment:

from(
  u in User,
  join: c in Contact,
  on: c.user_id = u.id,
  order_by: fragment("new_field")
  select: %{
    new_field: c.some_field
  }
)

My cursor fields can't find my new_field on my query during pagination but none option worked:

[cursor_fields: [{:new_field, :desc}], limit: 10]
[cursor_fields: [{"new_field", :desc}], limit: 10]

I also tried using but not had success

fetch_cursor_value_fun: fn
        schema, :new_field ->
          schema.new_field

        schema, field ->
          Paginator.default_fetch_cursor_value(schema, field)
      end,

I'm doing some mistake or it is just not possible to do it?