Resource.Action how to pass an argument to the prepare build()

I have a working Generic Action, but am trying to translate it into the Ash Read Action, less lines of code basically :slight_smile:

I can’t for the hell of me pass the resource.argument to the prepare build() thing.
I probably don’t grasp quite well the hidden pipe happening and the function variables scopes. (action/argument, prepare fn, build fn).
I tried both of the ways, but I can’t get em both to work.

Neither worked (as if Ash.Query doesn’t exist)
Neither passing any variables into prepare build( ) seem to work! -.-

read :get_distinct_values2 do
      argument :column_name, :atom, allow_nil?: false

      prepare build(select: ([^column_name])

      prepare fn action, context ->
        column_name = action.arguments.column_name
        |> Ash.Query.distinct([^column_name])

Welp! :slight_smile:

You might be able to do

 prepare build(select: ([arg(column_name)])

otherwise this should work

      prepare fn query, context ->
        column_name = Ash.Query.get_argument(query, :column_name)
1 Like