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

How to upsert multiple rows atomically?

How do you update multiple rows in one go, making sure each update is atomic and either all succeed or all rollback? My use case: updating stock for an item across several warehouses. ```...

How to load a limited amount of related records (and maybe store as virtual attr?)

Still pretty new to Ash and ran into some issues yesterday getting some data into my liveview. What I want to do is load a relationship when I fetch a collection of records, but only take the most recently inserted record. That would then either be accessed as something like a 'virtual field' on the main record or through the relationship (not sure what's best). How would I accomplish this? E.g. a Document :has_many :stats, and I want to load the accompanying, most recent Stat only (for each Document) whenever I fetch a Document collection. I tried something like the below but it was not valid--...
Solution:
I would probably go with a has_one with the from_many and sort options set

Child form is not automatically added when a `:union` type attribute has a `value` of `nil`

Im trying to create a Form using Form.for_update on a resource that has a :union type attribute where the value is nil: ```elixir form = AshPhoenix.Form.for_update( %Resource{union: %Ash.Union{type: :custom, value: nil}},...
Solution:
Created a PR to resolve the issue https://github.com/ash-project/ash_phoenix/pull/417...

Any pointers on testing authenticated LV's with AshAuthentication Magic Link?

I'm attempting to reproduce a similar workflow to the email/password instructions in the docs but am running into issues around confirmation add ons when combined with magic link authentication. My current setup looks like this, but is erroring with a Fails with AshAuthentication.Errors.CannotConfirmUnconfirmedUser: ```...

Actor can create data in other tenant

I'm testing wether a member of TenantA can create a project in TenantB. This test is failing (the :create is succeeding). I thought that multitenancy would block this case, but perhaps I'm confusing things. ```elixir test "member_cannot_create_in_other_tenant" do...

Edit error messages for Identity

Problem I have a User resource with an email identity constraint: ```elixir...

Use of current_tenant throughout app

I am trying to build a multi tenant app and currently have things working placing this socket.assigns.current_tenant in every place where I am about to do a query ``` def mount(_params, _session, socket) do form =...
Solution:
It makes sense but we don't do it that way on purpose. It can have strange side effects to do magical things like that.

Type error from ash_postgres for `{:array, :map}`

I have this resource attribute: ``` actions do defaults [:read, create: :, update: :] end...

Dependency conflict with mishka_chelekom when using the ash-hq.org installer





...

AshPhoenix nested form not populating

Hello! I ran into an issue with generating nested forms. I've read through the nested forms docs: https://hexdocs.pm/ash_phoenix/nested-forms.html#defining-the-structure but I can't seem to create a nested form for an optional has_one relationship. I have a resource Submission: ```elixir defmodule Feedback.Submission do...
Solution:
You have to add a form using AshPhoenix.Form.add_form

Conditionally run validations

Hey I have a UserFeedback resource that has questions & answers collected from users who provide feedback in my LiveView app via a create :provide_feeback action When determining whether to get feedback from a user I check if the changeset is valid, i.e. Ash.Changeset.for_create(UserFeedback, :provide_feedback, %{...}, actor: current_user).valid?...

How to return `401 Unauthorized` status when actor is absent in action?

I just started playing with phoenix/ash and I'm trying to create a simple json api with authentication. I managed to setup the authentication and use the bearer token to get the actor. I have a simple /me action that filters users resource to get the user with the same email as actor:...

Magic Link login fails due to nil tenant for master user

Hi sorry, In my system, I have a master user whose site_id is nil. When I send a Magic Link request for this user, it successfully finds the user and returns a token. However, the issue occurs when I click on the link — one of the queries throws the following error: ```elixir [debug] QUERY ERROR source="users" db=0.4ms queue=0.3ms idle=750.5ms INSERT INTO "users" AS u0 ("id","site_id","confirmed_at","email") VALUES ($1,$2,$3,$4) ON CONFLICT ("email") DO UPDATE SET "email" = EXCLUDED."email", "confirmed_at" = EXCLUDED."confirmed_at" WHERE ((CASE WHEN u0."confirmed_at"::timestamp IS NULL THEN ash_raise_error($5::jsonb) ELSE $6 END)) RETURNING "site_id","confirmed_at","hashed_password","email","id" ["eebf4165-82d2-4c8b-9890-f11808d29c59", nil, ~U[2025-09-05 21:39:04.145886Z], #Ash.CiString<"master@example.com">, "{"input":{"resource":"Elixir.MishkaCms.Accounts.User","confirmation_strategy":"confirm_new_user"},"exception":"AshAuthentication.Errors.CannotConfirmUnconfirmedUser"}", true]...
Solution:
🥳

minor QOL improvement

I want to change this in the igniter task so it's navigate by default, this allows for spa like navigation (it's already used in the new chat link) https://github.com/ash-project/ash_ai/blob/41fd0ef906f9438b7b8a42f8ec4c840fcae82bf1/lib/mix/tasks/ash_ai.gen.chat.ex#L1118...

newb question: what's the actual use case of `ash_rate_limiter`?

Hello! Sorry, maybe I'm writing a dumb question, but here I go: isn't rate limiting a web concern, meaning something that belongs to the "plug and phoenix" layer? Therefore, what does ash have to do with it? Why wouldn't I just use hammer, plug it in, and call it a day?...

Reactor dynamic steps usage?

In the docs it is described steps can be dynamically created, but I see no docs on what it is expected to return. Here is the example from the docs: ```elixir...
Solution:
Here is an AI generated answer because I'm short on time. I've had really good luck with deepwiki, and reviewed what it said and it looks correct to me 🙂 https://deepwiki.com/search/in-the-docs-it-is-described-st_b46a5a96-c14f-46e2-81b2-2ad48f05f42d...

Sub domain multi tenancy - have magic links include sub domain

Hi everyone. I am using Ash attribuite based multi tenancy with sub domains. The issue I am having is that when the user receives a magic link, the magic link contains only my main domain not the subdomain the user originally used. So the user should receive something like org1.myapp.com/[rest of magic link] but they only receive myapp.com/[rest of magic link].. Is there a way I can modify the links that are sent out or how should I work around this? Thank you
Solution:
The tenant should be available as an option in the sender.

Calculation Heavy Resource with Historian Retrieval

Hello, was needing some help on a difficult problem. I have a calculation heavy resource (100+ calculations) that we would like to grab data out of our 3rd party historian sensor tables and perform calculations on as well as filter the results of certain calculations for metrics purposes. For example we would want to get the temperature over the course of a run and perform the average over the whole run. One caveat is that the sqlth_data tables are created weekly and have dynamic names for the tables that are stored in the partition tables and due to the historian data from tables require complex time-based filtering and dynamic table names its breaking my brain. I can make this work with calculate but i was hoping to make this work via expr is there something i am missing or could do that would help out my approach? ``` def expression(_opts, _context) do expr(...
No description

** (Mix) Could not invoke task "igniter.install": 1 error found!--auth-strategy : Unknown option

Got this error when running the HQ ash installer command that was auto generated based on the config I selected.
Solution:
Solved it using Visual Studio Build Tools:) Im using windows 11...

How to (temporarily) disable data layer entirely

I know this looks weird, but - given a starter project, I would love to properly configure AshPostgres, and then to "comment out" it and swap with an in-memory (non actually persistent) alternative, e.g. Ash.DataLayer.Ets (even better if any accidental entry gets deleted in 24hrs). Use case: I just want to start and deploy a simple static HTML page that requires no logic, nor authentication. In the near future, as I develop features, I want to put them back in. But in the meantime, I want to deploy my app without actually spending $38 per month for a postgres db I would not hit (yes, I'm using fly.io). If I'm tackling this problem wrong, or if you suggest a better workflow, I'm all ears!...
Solution:
But also if you're just not going to be using the resources at all, you can just not start your repo