tellesleandro

tellesleandro

Following the documentation at Ash.Query — ash v3.29.3, if I write Ash.Query.build(LGS.Operacional.Estadia, limit: 1) |> LGS.Operacional.read, I get the following error

{:error,
 %Ash.Error.Invalid{
   errors: [
     %Ash.Error.Invalid.LimitRequired{
       changeset: nil,
       query: nil,
       error_context: [],
       vars: [],
       path: [],
       stacktrace: #Stacktrace<>,
       class: :invalid
     }
   ],
   stacktraces?: true,
   changeset: nil,
   query: #Ash.Query<
     resource: LGS.Operacional.Estadia,
     limit: 1,
     errors: [
       %Ash.Error.Invalid.LimitRequired{
         changeset: nil,
         query: nil,
         error_context: [],
         vars: [],
         path: [],
         stacktrace: #Stacktrace<>,
         class: :invalid
       }
     ]
   >,
   error_context: [nil],
   vars: [],
   path: [],
   stacktrace: #Stacktrace<>,
   class: :invalid
 }}

Ash version: “ash”: {:hex, :ash, “2.17.8”

What’s wrong with the query?

Thanks.

Showing Posts 1 to 10

zachdaniel

zachdaniel

Creator of Ash

I believe this is coming from having required pagination on the resource. Pagination limits should be specified as LGS.Operacional.read(page: [limit: 1])

tellesleandro

tellesleandro OP

I think I didn’t get it Zach. What do you mean by “having required pagination on the resource”. Is it something that I put in the resource Estadia? I followed the documentation at Ash.Query — ash v3.29.3, where :limit is one of the options.
I’m trying to write an action using prepare(fn input, context -> ... end), but I’m not succeding on paginating using keyset. Any guidance is welcome. Thanks.

zachdaniel

zachdaniel

Creator of Ash

Can I see the read action you’re calling? I’m suspecting that you have something like:

pagination keyset?: true

By default, when you add that, it makes pagination required. To paginate, you don’t provide the limit with Ash.Query.limit, you provide it as an option when reading, i.e LGS.Operacional.read(page: [limit: 1])

tellesleandro

tellesleandro OP

read :list do
  prepare(fn input, context ->
    Estadia
    |> Ash.Query.filter(localizador_externo: "123456")
  end)
  pagination(keyset?: true, default_limit: 1, countable: true)
end

I’m also trying to receive a list of tuples argument, like: [{"a", 1}, {"b", 2}, ...], but I couldn’t get the argument function to work.

zachdaniel

zachdaniel

Creator of Ash

There isn’t a builtin type for tuples, so you’d need to write a custom one and/or use the :term type to accept a value of any type.

Interesting, it seems like default_limit is not being applied.

zachdaniel

zachdaniel

Creator of Ash

I’ve just pushed something to main that might help. Please try it out and let me know.

tellesleandro

tellesleandro OP

I’ll try in a minute. Before that, could you help me with another question?
The following code

read :list do
      prepare(fn input, context ->
        query = Estadia
        |> Ash.Query.build(load: [
          :entrada_parceiro,
          :entrada_via,
          :faturamentos,
          :saida_via,
          entrada_plano_contrato: :pessoa
        ], limit: 1)

        filters = [
          {"localizadores", "123456"}
        ]

        Enum.reduce(filters, query, fn
          {"localizadores", value}, query ->
            Ash.Query.filter(query, value in localizadores)
          filter, query ->
            Ash.Query.filter(query, filter)
        end)
      end)
      # pagination(keyset?: true, default_limit: 1, countable: true)
    end

gives me the following error

{:error,
 %Ash.Error.Unknown{
   errors: [
     %Ash.Error.Unknown.UnknownError{
       error: "filter: Invalid reference value",
       field: nil,
       changeset: nil,
       query: nil,
       error_context: [],
       vars: [],
       path: [:filter],
       stacktrace: #Stacktrace<>,
       class: :unknown
     }
   ],
   stacktraces?: true,
   changeset: nil,
   query: #Ash.Query<
     resource: LGS.Operacional.Estadia,
     limit: 1,
     load: [
       entrada_parceiro: [],
       entrada_via: [],
       faturamentos: [],
       saida_via: [],
       entrada_plano_contrato: #Ash.Query<
         resource: LGS.Operacional.PlanoContrato,
         load: [pessoa: []]
       >
     ],
     errors: [
       %Ash.Error.Unknown.UnknownError{
         error: "filter: Invalid reference value",
         field: nil,
         changeset: nil,
         query: nil,
         error_context: [],
         vars: [],
         path: [:filter],
         stacktrace: #Stacktrace<>,
         class: :unknown
       }
     ]
   >,
   error_context: [nil],
   vars: [],
   path: [],
   stacktrace: #Stacktrace<>,
   class: :unknown
 }}
tellesleandro

tellesleandro OP

Even with the main branch, the action returns %Ash.Page.Offset{}.

zachdaniel

zachdaniel

Creator of Ash

You need to pin variable references, like so: Ash.Query.filter(query, ^value in localizadores)

tellesleandro

tellesleandro OP

Great. Worked. Thanks.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews