Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

Correct Way to Display Spark.Error.DslError?

Hi! I’m writing a custom DSL extension and I’m struggling with making Spark.Error.DslError show up in the right place. I followed patterns from core Ash code (like default_accept.ex and verify_identities.ex), and also looked at extensions like Ash Cloak. Here's what I did in my verifier: ```elixir...

Auth flow

I have an auth flow that I am wondering how I can best model in Ash. I have tens of thousands of members that I have the info of, most of which will not log into the app. Maybe up to 10 000 real users, some which will be very infrequent. So I would like to use the magic links only not have them manage a password. I also want people I don’t know the email address of to be able to log in, and fill some info to be reviewed by a human. Some even turn into volunteers but don’t want to become members. So they should be tracked in a different table....

Complex Custom Actions

How do you usually model complex operations over a model? I have a model that needs to do some processing over their inputs, it handles everything related to subtitles, and after creation it goes over several stages of analysis of the context and such and I'm struggling to fit it inside of the Ash framework. I was thinking to model it in two ways:...
Solution:
before_action hook or before_transaction hook depending on how costly the analyze_content() function is

Calculating average number of sessions per user

I have the following resource: ``` defmodule MyApp.Ash.Dashboards.SessionEvent do @moduledoc """ Resource that maps to Analytics DB session_events materialized view...

receiving an Ash Error and don't understand why

question about this error. I'm trying to setup something similar in my app that the Tunez book does. Following an artist, but I'm wanting to like a post. Here's the code ```elixir post.ex (resource) has_many :like_relationships, App.Elevate.PostLike...

Igniter stuck in loop on brand new install

I have a brand new install, when I run the command (provided by https://ash-hq.org/#installer), it gets stuck in an infinite loop of: ```setting up igniter ✔ compiling igniter ✔ setting up igniter ✔...

many_to_many in ash

```elixir defmodule Consola.Database.ShortUrl do use Ash.Resource, domain: Consola.Database, data_layer: AshPostgres.DataLayer ...

Question about somewhat unusual join relationship

Imagine we have User, Opinion and Event. Opinion is a join resource between User and Event. The tricky part that I want to support is for Opinion to have nullable user_id, where an opinion without a user is a default opinion. And when we query opinions/events for a user we want to include default opinions for events which the user has not specified/created their own opinion. Sounds like something for sort based on user_id and distinct based on event_id. And this combo does work if we query things for a single user but if we load things for multiple users there appears a problem - read action is used to read all users opinions together. Because of that it results in removal of a default opinion if any one of requested users has its own opinion (distinct gets applied to whole query not per user). Which means that if one user has its own opinion about an event then other users, who do not have their own opinion, lose their join link (default one). I'm interested if it is possible to make this work without using manual relationship....
Solution:
I think many to many relationships essentially only support join resources that are distinct on the two columns in question currently, we should probably be showing an error about it TBH

Book seed issue: Tunez.Music.Artist.read had no matching bulk strategy that could be used

When I try to run the first seed script for artists from the book code I get the following error message: ``` ** (Ash.Error.Invalid) Invalid Error ...

Framework Error - Assumption failed: Invalid return from calculation

Hi, I’m encountering a Framework Error with the message:
Assumption failed: Invalid return from calculation, expected a value, got %Ash.NotLoaded{}...

I want to load related records inside "relationships" key

Hi! I'm following the Ash book, specifically on loading related records: ```elixir json_api do type "artist" includes [:albums]...

How to use Ash.Notifier.PubSub filter?

The docs say the filter takes a function with the Notification as the argument and must return a truthy or falsy value. Does it work like this? ```elixir publish :action, "topic" do filter fn notification -> notification.data.status == :done end...
Solution:
Yes that looks right to me

Error message in a grapqhl mutation

``` == Compilation error in file lib/safari_web/graphql_schema.ex == ** (KeyError) key :error_location not found in: %AshGraphql.Resource.Mutation{ name: :supplemental_document_create, action: %Ash.Resource.Actions.Action{...
Solution:
looking at the commit that adds in the bit causing the error https://github.com/ash-project/ash_graphql/commit/4bcea7846fbcd752bce94047135ed83780f26204 and it suggests that you should have AshGraphql.Resource.Action structs but you have Mutation structs instead - so it might be defined in your schema incorrectly

Return only selected fields

How do i return only the selected fields instead of the whole struct? Cant seem to find a good example for the action based version ```elixir read :select_specific_fields do prepare build( select: [:id, :name]...

Ash Paper Trail, destroy action

I would like to know how to remove the versions of an object that I deleted. I have used a destroy action on a parent object. this parent object has a version system in place with the following configuration: ```paper_trail do primary_key_type :uuid...

Detecting nested form changes

What is the best way to determine whether a form has changed or not? Let's say I have a nested form for an album and nested tracks where I only modify one of them. I want to send a notification about only the track that changed using pubsub, but it appears that the pubsub event is emitted for all tracks in that album including the ones that didn't change.

Guidance on Dynamic Filtering, Sorting, and Pagination

Hello Ash community, I'm implementing standard filtering, sorting, and pagination features for my contacts module and have defined a read action as follows: ```elixir define :list_contacts, action: :read...

open_api_spex spec declaration with ash_json_api

generated Open API spec has either some basic or nil descriptions, summaries, etc. open_api_spex documentation suggests using macros like operation/2 to describe my API. i've searched ash_json_api docs for some information but to no success. is there a way to do describe my domains' / resources' routes like so in ash_json_api?
Solution:
You add descriptions to the attributes and actions etc. directly

Changeset truncates Time, DateTime and NaiveDateTime to whole seconds

Ash 3.5.8 is removing microseconds from Time, DateTime and NaiveDateTime, which I think is a bug. I've noticed this in a create changeset. For example ~U[2025-05-09 08:02:21.294214Z] is truncated to ~U[2025-05-09 08:02:21Z].

Policy breakdowns for fields

Is it possible to get a policy breakdown for an Ash.ForbiddenField in a record returned by a read action?
Solution:
I think they can be logged with log_policy_breakdowns but not retrieved from a forbidden field.
Next