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

Cannot find the right binding when sorting by fragment in many_to_many

``` has_many :semantically_similar, MODULE do no_attributes? true sort [...

Cinder doesn’t paginate

I’m trying to get cinder to paginate but it shows all data regardless. Cinder version: 0.5.5 <Cinder.Table.table...
Solution:
Does your resource definition enable pagination for the relevant action?

Can the Admin UI show calculations?

I have two resources; One acting as a course template and one for actualized, planned courses. Both have a price attribute with the intention that if an actualized course does not have a price it will use the default price from its template. This works fine when looking at the result of a read action in iex but the Admin UI doesn't want to show that calculation anywhere. Is this just not part of what AshAdmin is meant to do? This is not really a breaking issue as I will have to write my own dashboard UI on top of this anyway, it would've just been nice to be able to quickly check AshAdmin to see if changes in my resources work as intended....

Automatically Loading a Calculation by Default

Is there a way to always load a calculation by default without having to specify it every time?
Solution:
there is the build preparation you can use ``` read :read do prepare build(load: [:calculation])...

Execute an after_action only on single action or customize it for bulk actions.

Hello! I have an resource that must send a push notification when one of it's push notifications are updated. The problem is that I should aggregate bulk actions and send a single push notification in cases where multiple records go to the same user (which is the related resource). I tried to look on the internet and on this forum for a way to do that but couldn't find anything. But It would be something like sending a message saying that a user has "X 'something' to work on" (in case of bulk) vs saying "You have a 'something' to work on" and I don't want to spam the users with a message that meant to be sent for the single relationship update when we're doing bulks....

Possibly wrong `numericality` validation in `tunez` repo

Hello, I know this is a bit silly but considering that it's being accompanied by a book I thought I'd let you know that, unless I am misunderstanding something, in the Album Resource the year_released validation is slightly off. https://github.com/sevenseacat/tunez/blob/81078dc05cf42fa80945c33b6f90debab76700b2/lib/tunez/music/album.ex#L75-L80 The year must be in the range (1950, next_year), whereas currently it validates it to be in the range (1950, next_year]....
Solution:
huh. you're right! the message is slightly incorrect - but the code reflects my intention

Best way to handle actors/roles

Hi everyone! 👋 We’re working on a multi-app Phoenix project and could use some advice on unifying authorization actors. Setup...
Solution:
Gotcha, so normalizing them into a single struct makes perfect sense

How do I use a custom assign in the AshAuthentication success callback to work with Ash.Scope?

I’m using AshAuthentication and I have a success/4 callback in my AuthController that looks like this that is attempting to set the current_user key in the Scope object as part of the authentication confirmation flow: ``` def success(conn, activity, user, _token) do return_to = AuthRedirect.post_login_path(user)...

Recognizing Phoenix.Endpoint when using SiteEncrypt.

Would it be possible to recognize the endpoint if one is using SiteEncrypt?
The use statement is then use SiteEncrypt.Phoenix.Endpoint, otp_app: ... instead of the regular one. this causes packages like tidewave to not recognize the endpoint....

AshAuthentication + custom api login = ?

I want to create a custom authentication flow for a simple POST /api/auth/login endpoint where I get the username and password from the user of the API. I've found the example of how to write an APIAuthController pasted below, and I've put it in its own file in my project, but I don't know how to fit this into my router, what's the next obvious step that my tired and caffeine fueled brain doesn't realize? I had a talk with both ChatGPT and Claude.ai about this too, and they sent me down one rabbit hole each, so this is getting exciting! 😄 ```elixir...

Cascading delete and pub_sub

Hi @everyone, I have a resource (Notification) ```elixir ...
Solution:
anytime 🙂

Password reset error when using Sqlite

On a newly created Ash project using Sqlite I get the following error when attempting a password reset: [debug] QUERY ERROR source="users" db=0.0ms idle=444.2ms UPDATE "users" AS u0 SET "confirmed_at" = CAST(CAST(? AS TEXT) AS TEXT), "hashed_password" = CAST((CASE WHEN REGEXP_REPLACE(REGEXP_REPLACE(?, ' +$', ''), '^ +', '') = ? THEN NULL ELSE REGEXP_REPLACE(REGEXP_REPLACE(?, ' +$', ''), '^ +', '') END) AS TEXT) WHERE (CAST(u0."id" AS TEXT) = CAST(? AS TEXT)) RETURNING "id", "confirmed_at", "email", "hashed_password" [~U[2025-08-20 19:00:06.675262Z], "$2b$12$fFi1OtgfaPfaDBLQHyz3h.fS3bjMSUUgXVMl9h5UVBm8rocZELAea", "", "$2b$12$0C5BBQvboelGhbfi3n/3geoEf/0AQbwMOEZlpWNNqoh8btxY/qe1K", "6da84435-84cd-4827-8ec9-55c56b08dc5e"] ...

How can add an action in Mixin?

Hi sorry, this is my Mixin to create version for my records, how can add an action inside it? ```elixir defmodule MishkaCms.Runtime.Resources.Mixins.PagePaperTrailMixin do def postgres do quote do...
Solution:
yes, that should work

Not sure how to apply a policy on an attribute of a resource. Keep getting an error.

I have a policy for a resource called user_tokens which is just a way to test a user sign up. User enters phone number and user_tokens will save and send an otp to the mobile number. To avoid abuse, there is a status column which when "locked" should stop sending the SMS. I tried the things as the error suggested but could not overcome the problem yet. Also searched the prior posts but yet to find an answer. Very new to Ash, but hopefully I am not bugging and taking up much of your time in the process of getting past my learning curve. Apologies if I am. ``` policy action_type([:create]) do forbid_if expr(status == :locked)...

Master user token can not update/destroy a global false multi-tenancy resource

Hi sorry, I think have a mistake in using actions Imagine you are a master user (has who has not tenancy ) , now you want to update a a global false multi-tenancy resource record! So because it is master user and has no tenancy i created :get_any action, my code set tenancy nil for master user on plug level ...
Solution:
You'll have to use generic actions for a lot of things in that setup

is it possible to use AshApi schema-less

I just wanna use the DSL to define business logic routes, without interaction with database is it possible?...

Migrations are applied incorrectly with multiple repos

Hi all 👋, I’m working on a project that uses multiple Repos to avoid pool exhaustion. I ran into the issue described here on ElixirForum: 👉https://elixirforum.com/t/migrations-are-applied-incorrectly-in-all-repos/61082 ...

Improving incremental compilation times

Hi there! I need to know what the best practices are when working with Ash resources and related files (calculations, preparations, etc), specifically around avoiding unnecessary dependencies and keeping compilation times low. Things to do, and what not to do. I originally posted about this on the Elixir Forum (https://elixirforum.com/t/reducing-incremental-compilation-times-in-phoenix-ash-project/72113). The feedback there helped me better analyze my codebase and realize that I may be doing something wrong within Ash resources — and related files — myself, which has increased recompilation times (up to 10s). My gut is telling me that what I'm doing here might be wrong:...
Solution:
```elixir defmodule Your.Resource.Changes.SendInvitationEmail do use Ash.Resource.Change def change(changeset, , ) ->...

Embedded Resource default value causes compilation error

I have a fairly simple embedded resource: ```elixir defmodule App.Organizations.OrganizationSettings do @moduledoc false ...
Solution:
default: fn -> %{} end in this case

Cancel job Ash Oban

Is there a correct way to cancel a job in ash oban? Specifically, I'm trying to cancel the :respond job in the generated chat in Ash AI if the user wants to stop the response like in other AI chat apps...