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

Windows has problems PendingCodegen after `ash.setup`

Hi in mac os i have no problem. in windows when My colleague clone the project and fresh install (after create db and migrate all migrations) , it gets this error in my phoenix project! (without any new changes) or changing anu resource code! ``` mix ecto.drop; mix ash.setup; mix run priv/repo/entry_dev_test_seeds.exs ; iex -S mix phx.server ...
Solution:
I just honestly don't think I have the bandwidth to support windows at this point, someone else will have to figure out this strangeness
No description

Confusion with before_transaction timing and doing changes before manage_relationship

Hello, I am basically trying to use the data from a third party API call to create a related resource in manage_relationship. Reading the doc I decided that it would make sense to call the API in a before_transaction hook. The docs is stating the following execution order for a create action: ```...
Solution:
Changes/validations run and then when you call the action before_transaction hooks are the first hooks to run

Conversion of strings with just whitespace when storing in postgres

We are moving data from old systems to a new system and noted that one entry had a tax number of " ". Now, that is not a valid tax number, but we realized that the corresponding DB row has a value of null instead. Is this the default behaviour for strings that contain only whitespace? Is there an option to disable this behaviour and what are the caveats if we do?...

manage_relationship not creating many-to-many join records

I'm having trouble getting manage_relationship to work with a many-to-many relationship where the destination resource uses a non-standard primary key. Setup I have a many-to-many relationship between Device and Pass through a DeviceRegistration join table:...

Drastic slowdowns

Hi! I'm getting crippling slow responses from Ash for simple queries. For example: ``` [debug] HANDLE EVENT "sort" in TalksWeb.OutlineIndexLive Parameters: %{"field" => "title"} ...

Guides for using ashflow

Can't find any guides on how to use ashflow, and the documentation doesn't specify anything

Aggregates based on resources keep failing

```elixir defmodule YourApp.Poetry.Topic do alias YourApp.Poetry.Poem use Ash.Resource,...

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:
🥳