Ash Framework

AF

Ash Framework

The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.

Join

support

showcase

today-i-learned

Modifying the argument clashes with AshCloak changing the argument's type

Hello! I have a resource Platform with an attribute called credentials I want to have encrypted. This attribute is a union of embedded resources (representing credentials for different platforms). I have a change that sets the type attribute on the credentials union changeset to the same value as the platform.type is set - to avoid having to pass the same value twice and ensure the credentials type matches the platform type. After adding the AshCloak encryption, it replaces my argument :credentials, :map with its own argument typed as a union.This causes my change to fail, because:...

How to set user as actor after login?

When logging in with the sign_in_with_password action provided by AshAuthentication, I would like to set the loaded user as an actor so that it is possible to apply policies and load relationships already at login.

Changing attributes in action

I am trying to simplify the commented out code by using expr() , but i get an InvalidAttributeError with the hint string_downcase(nil) ```ex create :create do accept [:name]...
Solution:
You can't use expressions in that context

How to write a policy to ensure the user belongs to the tenant through a membership relation?

I have read many examples on multitenancy implementation with Ash, but most of these examples assume that the user belongs to one tenant. In my case, a user can belong to one or more tenants and can switch from one to another using a select list. We therefore have three resources, Organization, User, and Membership, to make the connection. Our application mainly uses a JSON API where we pass an authentication token in each request, as well as a custom X-Org-Id header with the current tenant ID the user selected....
Solution:
You should be able to create a SimpleCheck that can confirm that the actor has a membership for the tenant though: https://hexdocs.pm/ash/Ash.Policy.SimpleCheck.html#content

Anonymous Function Queries (Preparations)

I can't seem to get the syntax right, what am I doing wrong? ``` preparations do prepare fn query, context ->...

Loading data from an external API for a calculation

Hello! I have a resource that I would like to enhance in certain reads with a calculation that needs to be based off data from an external API. I'm mindful of not wanting to make the API request from within a transaction if possible. I thought of adding a preparation to the read action that will fetch the API data and put it into the context, which the calculation can use. ...

Flattening Polymorphic Relationships in Ash GraphQL

Hey folks 👋 I’m working with polymorphic relationships in Ash and followed the guide here: https://hexdocs.pm/ash/polymorphic-relationships.html. I tried exposing it through the GraphQL API, and I’m a bit unsure if there’s a way to shape the schema the way I want. Right now, when I query bankAccounts, I get something like this:...

Ash Auth For Inertia Setup & Ash Auth vs Ash Phoenix Auth

Hi everyone! So I have been playing with the mix phx.gen.auth in my Inertia setup and was wondering: a) Am I losing anything if I don't use Ash Auth yet if I already has my auth configured from the phx.gen.auth since I can just pass the right scope for the actors when using Ash? I am migrating my models to Ash resources now but I need to understand how the ash auth works in tandem with the ash resources as a whole. b) For the auth vs phoenix auth, I assume phoenix auth is just the UI/liveview + routes scope on top of the ash auth? I can still build my own routes with Inertia rendering and use the auth module to trigger the auth internally right?...
Solution:
you can just use your generated auth, Ash doesn't really care to much about what you pass in as an actor, your policies just need to know how to work with it. I've used ash with our own custom auth before ash_authentication was a thing, worked without a hitch.

ash_authentication_live_session dups

After implementing Ash.Scope, it occurred to me that I'm sort of duplicating assignments with current_user as it's also set via ash_authentication_live_session. Is this generally just how folks do things for convenient access in the view or should I be deduplicating somehow? I feel like I shouldn't care but it bothers me on some level lol. Thanks!

Cross schema many_to_many

Hi, I have two resources let's say A and B, A is using :context multitenancy, B is in the public schema. I want to have a many_to_many relationship between A and B, using a AB resource that also is using :context multitenancy. The issue is that when I try to load the B records directly from A (MyApp.get_a(a_id, tenant: tenant, load: [:bs]), The query generated tries to join with an AB table from the public schema, which does not exist as it is a multitenant resource. Did I miss something or is it a bug ? Loading through the join resource does work though (MyApp.get_a(a_id, tenant: tenant, load: [abs: [:b]])...

TypedStruct with array and default

I have a typed_struct with an {:array, OtherStruct} field. Passing data to new() works as expected but after adding default: [] to the field, the field only returns []. I'm not sure if this is a bug or intended. Structs: ```...
No description

Ash.Notifier

Is there a way to have a parametrized notifier, just like with validators/preparation/changes

AshJsonApi: Can a domain support routes for different endpoints/routers?

I'm looking into exposing some API routes only for my internal network, which won't be publicly accessible. Is it possible to configure routes to be exposed for one or more endpoints/routers? i.e. Some routes are public only, some private only, others are both.

Usage rules task not found

Hi! Did something break in usage_rules? I'm getting this all of a sudden: ** (Mix) The task "usage_rules.sync" could not be found It's in a clean new project. After running ash.setup, the next thing I always do before starting to work on the project is generating the AGENTS.md file. Always worked fine until now...

Having a small policy that doesn't seem to ever be called

I have a policy where I need an actor to be present for three different actions, but the policies don't seem to be called. The policies: ```elixir...
Solution:
yeah, in this context, the policies don't guarantee an actor. you could wrap this in before_action and than you'd know that if you reach the hook that there is an actor beccause of the policy, or you could just handle the actor being nil case Map.get(context.actor || %{}, :group_id) do which i would probably do

Ash AI not working

Failed to JSON decode error response. ERROR: %Jason.DecodeError{position: 1005, token: nil, data: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'tools[0].function_declarations[0].parameters
Failed to JSON decode error response. ERROR: %Jason.DecodeError{position: 1005, token: nil, data: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'tools[0].function_declarations[0].parameters
with this ```elixir...

Missing __spark_metadata__ field in Ash.Notifier.PubSub.Publication struct

After upgrading to Spark 2.3.4 and Elixir 1.18.4, I’m seeing the following warning: warning: Entity without spark_metadata field is deprecated. Entity Ash.Notifier.PubSub.Publication does not define a __spark_metadata__ field. This field is required to access source annotations. Add __spark_metadata__: nil to the defstruct for Ash.Notifier.PubSub.Publication. (elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2 (spark 2.3.4) lib/spark/dsl/extension.ex:2135: Spark.Dsl.Extension.after_verify/1...

no function clause matching in Pgvector.new/1

This is what I'm doing: ```elixir case Req.post(url, json: body) do {:ok, %{status: 200, body: %{"embeddings" => embeddings}}} ->...
Solution:
i think pg vector package is the issue

Ash AI writeable error:

``` vectorize do attributes description: :description_vector embedding_model CoffeeViewer.EmbeddingModels.Gemini...
Solution:
Well, you made it writable? false
Next