Ash FrameworkAF
Ash Framework7mo ago
104 replies
Leandro Pereira

Is it possible to convert policies expression to Ecto expressions?

Kinda of a weird request but I'm wondering if it's possible to resolve the policies expressions so I can reuse them in a regular Ecto query.

I started with this code but I'm new to Ash and a bit lost here:

    query = Ash.Query.for_read(MyApp.Resource, :my_query, actor: actor)

    authorizer = %Ash.Policy.Authorizer{
      actor: actor,
      resource: query.resource,
      action: query.action
    }

    {:filter, _authorizer, filter} =
      Ash.Policy.Authorizer.strict_check(authorizer, %{
        domain: MyApp.Domain,
        query: query,
        changeset: nil
      })

    # add_filter_expression doesn't work due to missing __ash_bindings__ field
    AshSql.Filter.add_filter_expression(query, filter) |> dbg


I'm aware that's private but that would ease the migration process. I can give more context if needed.
Was this page helpful?