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

Error when using before_action hook to set required relationship attribute

I'm using a before action to lookup and set the :state_id by the state's name or code. However, the change doesn't seem to be running as I never see the Logger.debugs and I get changeset errors that :state_id is required. Have I misconfigured this hook?...
Solution:

`change manage_relationship(...type: :remove)` not working

I have a many_to_many relationship between Organization and SubscriptionPlan. The Organization has the following two actions: ```elixir update :subscribe do argument :plan, :struct, constraints: [instance_of: SubscriptionPlan]...
Solution:
So the mistake I was making was in my accessing_through policy: ```elixir policy accessing_from(MyApp.Accounts.Organization, :subscribers) do authorize_if always()...

ash_sqlite: Error when querying on an inline code calculation

Hey there! I'm trying out ash_sqlite on a toy project, and I'm encountering an issue which seems to boil down to querying a calculation defined as inline elixir code. Here is the error (full stacktrace in the next post), followed by some relevant code. Happy to add more context if required....
Solution:
You can't filter on calculations that don't define an expression

Counting Related Records with a Virtual Field in a Multi-Tenant app

In a multi-tenant application, when retrieving records from the database using a read action, is there a way to define a virtual field that counts the number of records in the database? For example, something like: ```elixir calculate ...

Error using AshArchival

I'm getting this error when attempting a read onto a ressource:
** (UndefinedFunctionError) function AshArchival.Resource.initial_state/4 is undefined or private
** (UndefinedFunctionError) function AshArchival.Resource.initial_state/4 is undefined or private
...
Solution:
Sorry actually ! I added it as an authorizer instead of an extension 😩 my bad for this...

Use arguments in Relationship

I would like to pass some arguments to a has_many relationship, which would be provided by a read action. `actions do read :list do argument :start_in, DateTimeUsec, allow_nil?: false...

Bind variables in queries

Had Gemini 2.5 Pro rewrite an adaptation of the ash_ai semantic_search usage rule example. ```elixir prepare before_action(fn query, context -> config = get_search_config(query.arguments) ...

`on_match: :error` should error on unique key violation?

Hi, I want to make an invitation accept action, invitation has a relationship member which is a belongs_to from Member, it has user_id, entity_id, which is a unique pair, I want to make accept create a :member relationship, so if a user accepts an invitation that is already in entity, it will throw unique identity violation This is what I have ```ex...

Thoughts on updating `ash_geo` to follow current ash extension patterns?

I'm considering using ash_geo, but noticed it doesn't use the same patterns extensions like ash_money for installing postgres extensions and types. I know it's not owned by the ash-project org, but wanted to see what people thing about giving it an overhaul to have a nicer installation experience and follow current extension patterns.

How do cleanly do action accepts for resources with a lot of attributes without `:*`?

With :* being deprecated in the future major version of Ash. Will you have to put all attributes in the accepts for the actions need to support all attributes? The answer very well may be you just have to list all the attributes in the action. But wanted to check....
Solution:
default_accept in the top level actions block

Is there a way to not sign in users automatically after they register ?

I'm having that behavior by default
Solution:
The first one I'd suggest is to just have a plug after the user is set from the session that redirects all unconfirmed users to a page that says "please confirm your account"

Change in how `Ash.Changeset.force_change_attributes` handles `nil` values?

i'm currently in the process of upgrading to the latest version. there seems to have been a change in how Ash.Changeset.force_change_attributes handles nil values? at least, that what i seem to be observing. here's a simple example:...
No description

How do I use a Union type as an action argument?

Given the following module and union type: ```elixir defmodule Insi.Subscriptions.SubscriptionPlan do use Ash.Resource......
Solution:
You can't use the tag/tag value for types that aren't maps

Adding a custom sort

I have a field which is an atom. I want to sort it with a custom sort order: I am imagining something like this but I can;t find the exact syntax: prepare fn query, _ -> query...

Return a single record from a manual read

I'm using a manual read action to wrap an api client around a resource I want to fetch an indivdual record but the get? true only applies to the data layre, how can I instruct the action to return a single record?

Create a ressource with multiple relationships

The docs specifiy how to create a post -> comments relationship (so in the same direction as the has_many relationship But I couldn't find how to create a ressource that has multiple belongs_to With the post -> comments example,...
Solution:
And write the ids. Or you can use the argument + manage_relationship pattern which you can see in the relationships guide

ExUnit async: true {:error, :table_not_found} with Ash.DataLayer.Ets

I've recently done a refactor on a test suite to allow all cases to run asynchronously. Unfortunately at some point I've started getting intermittent :table_not_found errors thrown on the actions of an Ets backed resource. It's almost guaranteed to happen when the whole suite (200+ tests) runs asynchronously. Is this expected? Meaning Ash.DataLayer.Ets isn't ready/meant to be used with asynchronous tests or am I missing some proper setup? For reference, these Ets backed resources serve as an in-memory cache to avoid hitting the DB constantly. The main use-case is to cache actor/account permissions to be used by policies....

Trouble with relationships and form

I have the following: ``` update :post_task do argument :task, :map do...

With AshPostgres, what is the proper way to create a exclusion constraint in a ash resource?

For check constraint, we can do it like this ``` postgres do table "rate_plans" repo MyApp.Repo...

Trouble Understanding Reactor

I'm taking a stab at implementing a Reactor, but the documentation isn't very clear. I've read both the Reactor documentation and the AshReactor documentation for getting started, but I'm still getting tripped up. Here is a basic example: ```elixir defmodule MyApp.Accounts.Reactors.RegisterUser do @moduledoc false...