Pagination doesn't work in action

When execute prepare in an action read, the pagination doesn’t work.

read :list do
      argument(:filters, :term)

      prepare(fn input, context ->
        query =
         Resource
          |> Ash.Query.to_query()

        Enum.reduce(input.arguments.filters, query, fn
          {"title", value}, query ->
            Ash.Query.filter(query, contains(title, ^value))

          filter, query ->
            Ash.Query.filter(query, ^filter)
        end)
      end)

      pagination keyset?: true, default_limit: 20, countable: true
    end

Resolve. I’m include

read :read do
      primary?(true)
      pagination(offset?: true, default_limit: 20)
    end

The first argument to prepare in a query is the query itself.

      prepare(fn query, context ->
        Enum.reduce(query.arguments.filters, query, fn
          {"title", value}, query ->
            Ash.Query.filter(query, contains(title, ^value))

          filter, query ->
            Ash.Query.filter(query, ^filter)
        end)
      end)
1 Like