So my Paginator pagination query works fine until I append:
select: %{media_item: m, channel: chan}
to:
from(m in MediaItem,
join: con in ContentMediaItems,
on: m.id == con.media_item_id,
where: is_nil(m.published_at) == false,
join: chan in assoc(con, :channel),
where: chan.id == con.channel_id,
join: org in Org,
on: m.org_id == org.id,
where: org.slug == ^org_slug,
order_by: [{:desc, :published_at}],
preload: [:mediaitemartifacts],
select: %{media_item: m, channel: chan}
)
If I nest the result like that, the cursor will result in a nil value:
# RuntimeError at POST /rest/channel/latest_uploads_media_items
Exception:
** (RuntimeError) unstable sort order: nullable columns can't be used as the last term
(paginator 1.1.0) lib/paginator/ecto/query/asc_nulls_last.ex:8: Paginator.Ecto.Query.AscNullsLast.build_dynamic_filter/1
Is there a way to sidestep this so that I can return a nested result? Here is my paginate():
%{entries: entries, metadata: metadata} =
Repo.paginate(
query,
include_total_count: true,
after: after_cursor,
sort_direction: :desc,
cursor_fields: [{:inserted_at, :desc}, {:id, :asc}],
limit: limit
)