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

Generated attributes on update?

I've got a table using a generated value (GENERATED ALWAYS) which can change on updates. generated? true only appears to affect inserts. I'm guessing there is a toggle somewhere to handle this maybe? Even if there's just a way to tell an update action, "Hey, definitely get the return value on the update for this one," that would also be perfect. I didn't see any obvious way in the DSLs but... that doesn't mean much, lol....

(ArgumentError) could not fetch application environment :ash_domains for application :test

I just ran the startup script, here: https://ash-hq.org/#get-started But after pasting the command, I straight up get this error message ``` [info] == Migrated 20250829135349 in 0.0s...
Solution:
Please open issues describing the exact steps to reproduce each issue and I will look into it. You should be able to install packages into a new app one at a time to avoid the issues for now.

How to allow only one action and forbid all others by default in policy?

From the doc when multiple policies apply to the same request, all applicable policies must pass for the action to be authorized. I have a policy for the :profile read action, that is available only for the current actor: ```...
Solution:
forbid is the default, if no policy block applies to the action, so you can just remove this one ```elixir policy always() do forbid_if always()...

Resource actions - Transaction

Hi! I am currently working on some :create actions where I have SQLite3 as the datalayer. I have both before_action, manage_relatonship and after_action and I was expecting the whole create action to fail and the transaction to rollback if any of the changes failed. But this does not seem to be the case..?...

graphql subscription triggered by association

I have this subscription on the user resource ``` subscriptions do pubsub __.Endpoint...
Solution:
At the moment I think the only way would be to have a change that updates the user resource as well to trigger the subscription or have 2 separate subscriptions on the client.

Sorting on the first relationship in an aggregate

I want to do an aggregate over a m2m table where the order is important, so I write the code below but whatever I do I can't seem to sort on the first table. Should I be able to do that? ```elixir aggregates do list :phone_numbers_list, [:some_many_to_one_table, :user], :phone_number do...
Solution:
tldr: Calculations ❤️ The solution was to use a calculation on :some_many_to_one_table that got the phone number: ```elixir...

many to many relationship + PhoenixForm + checkboxes

I got the form working - eg; it saves the data in the many-to-many table when I submit the form - using a multi select field. Now I'm trying to figure out how to use checkboxes to create the form. I'm having a hard time to understand how I need to declare the checkboxes so that ash can understand which checked checkbox represents what record. I appreciate any sugestions, or pointers to reading materials - tutorials, articles, docs....

AshAuthentication failures with custom LiveViews

Hello, I want to have my own custom LiveViews for my auth routes, and I read https://alembic.com.au/blog/customising-ash-authentication-with-phoenix-liveview which was very helpful. I am aware of the overrides, but I don't really like them. Here are some relevant code snippets: ```ex...
Solution:
I just figured it out 🙂 If someone could explain why the following worked, that would be awesome! The issue was that originally I couldn't sign in nor register....

Confirmation broke, probably when the new confirmation button was added

When the confirmation button is clicked I see this error: ``` Plug.CSRFProtection.InvalidCSRFTokenError at POST /auth/user/confirm_new_user invalid CSRF (Cross Site Request Forgery) token, please make sure that: ...

Protecting against infinite loops on loading relationships

In my business domain I need to richly relate (i.e. with data on the relationship a resource with any number of resources of the same kind. I do this using a 'connector' resource, where the resource has_many connector forward_relationships and reverse_relationships, and the connector belongs to each of a source and target resource. So the source resource forward_relationship[]'s run through the connector resource an appear as reverse_relationship on the target. This enables me to model forward and reverse relationships independently, which is useful since they have independent lifecycles. The problem I'm having is that when I establish both forward and reverse relationships, if I have a load statement that loads relationships, then Ash will loop infinitely, exercising the datalayer over and over as it recursively loads resources it has recently loaded. As I mentioned the source and target resource are the same resource kind, so are constrained to have the same load statement....

AshPaperTrail - change module name and migrations are not genearted

1. Is it possible to change autogenerated module suffix Version to something different? 2. I have added AshPaperTrail and configured it to resource. But mix ash_postgres.generate_migrations --name add_paper_trail detect not changes so no new tables in migrations are added. And now I have error after updating resource that ERROR 42P01 (undefined_table) relation \"xxx_versions\" does not exist...
Solution:
I don't believe there is a way to customize the name right now no

[warning] Authentication failed: Query returned no users

🆘 Ash Authentication Policy Issue - SignInPreparation Query Failing I'm having trouble with Ash authentication where sign-in attempts fail with "Query returned no users" even though users exist in the database....

"Comparing values with `nil` will always return `false`" warning after updating ash 3.5.34 to 3.5.35

So I updated the deps today and I get a lot of these warnings. warning: Comparing values with nil will always return false. Use is_nil/1 instead. In: nil != {:_ref, [], :current_stop_id} (ash 3.5.35) lib/ash/changeset/changeset.ex:973: anonymous fn/2 in Ash.Changeset.atomic_default_condition/3 (elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3...

Atom type `cast_stored/2` doesnt use `unsafe_to_atom?` constraint

The cast_input/2 function (https://github.com/ash-project/ash/blob/75a5d8617a5814b3113b9cb3c646dfc687b768dc/lib/ash/type/atom.ex#L86) for the Ash.Types.Atom allows for unsafe parsing of the input value. The cast_stored/2 function does not have this functionality: https://github.com/ash-project/ash/blob/75a5d8617a5814b3113b9cb3c646dfc687b768dc/lib/ash/type/atom.ex#L106 ...
Solution:
https://github.com/ash-project/ash/pull/2292 One CI check fails but that seems to be a transient issue...

AshPhoenix - Union: "is not a map" error

I can't figure out why these params don't work: ```elixir %{ "access" => %{...

GraphQL incorrect input generation

Hi folks, I've got a really weird one. AshGraphQL is generating incorrect inputs for one of my resources, and I'm completely stumped why. I've got a triple-nested embed, where the top level is PG, the rest are embeds. Component - attribute :colors -> ColorInfo...

How to test policies correctly?

Hello, I am confused a tiny bit about policy testing. As an example, right now what I do is the following: ```ex...
Solution:
You can use Ash.can or for code interfaces their can_ variant

AshCloak - How do I decrypt?

I can't for the life of me figure out how to decrypt and read back a value that's encrypted and stored with AshCloak. I'm sure it's very simple ... just ... ahhhh!!

Using AshAuthentication in an embedded React /JSON API setup

Good day! I am a recent Phoenix/Ash convert and having a lot of fun with the whole ecosystem. Thanks for all the hard work! I have a Phoenix application that renders a React SPA application on a static path like /app. The authentication works seamlessly. ...

Cannot find the right binding when sorting by fragment in many_to_many

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