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

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.

Filtering by/selecting calculations when working with direct ecto queries

I have a use case where I'm needing to reach for Ecto directly. I'm trying to see if it's possible to filter by a calculation (or even just select it) when doing this. I can of course duplicate my calculation logic, but looking for a way to avoid that if possible 😅
Solution:
Nope 😄

After-commit hook?

I'm running into a race condition issue when I insert a row to a table with the resource's create action, and the subscriber to the notification calculates the resulting row count. What's the right way to do this in Ash? Adding 'Process.sleep(1000)' seems to help but I'm hoping there is a better way. Thanks.

soft delete - identity issue

i have a resource, for which soft delete is on, the resource has a field: :deleted_at. If I do not add this field to the identity, on creation the data is validated to be unique, but if I (soft) delete a record, than I can not create another one with the same unique fields. If I add the field to the identity, on creation the data is not validated correctly, since it includes the deleted_at null field....

Getting the old Inspect behaviour in ash 3.5.8

The changelog for 3.5.7 states that one case use hide_inspect_fields and such to customize the Inspect output, and also that calculations and aggregates will be removed when empty. I'm on ash 3.5.8 and I see none of that in IEx (hide_inspect_fields is accepted but ignored, and I have aggregates: %{} and calculations: %{}). Is this expected in IEx? Anybody else has the same issue?...
Solution:
Yeah it's a bug will be fixed in the next release

nested form issue

Hi Guys! I am trying to apply a simple nested form, and I can not get through. The use-case is simple: I want to add supplier_prices to my users. I tried to do everything according to the docs, probably missed something....

Rendering AshPaperTrails

Is there a good way to render the change history for a resource recorded by AshPaperTrail?
Solution:
In my Member ressource, I have: ```paper_trail do primary_key_type :uuid only_when_changed? true change_tracking_mode :changes_only...

`:read`ing random entry

meow! i'd like to ask a possibly dumb question. i am currently making an inspirational quotes API. i have a /api/quote endpoint with :random action which pretty much speaks for itself - returns a random quote and its author how should i correctly define my :random action? i know how to fetch a random entry using Ecto from q in "table", order_by: fragment("RANDOM()"), limit: 1, select: q. how would i do this in my action? i am using sqlite btw and here's my resource definition ```elixir use Ash.Resource, domain: App.Domain,...
Solution:
prepare build(limit: 1, sort: Ash.Sort.expr_sort(fragment("RANDOM()")))
prepare build(limit: 1, sort: Ash.Sort.expr_sort(fragment("RANDOM()")))
...

Custom Authentication Flow with AshAuthentication in Phoenix + React (Inertia.js)

Hi everyone! I've been implementing a custom authentication flow using AshAuthentication with Phoenix and React via Inertia.js. I wanted to share my approach and ask for feedback, especially regarding password reset functionality. Working Authentication Actions So far, I've successfully implemented the following actions defined by the AshAuthentication generator in my User Resource:...

Is there a way to do a 'limit' on a relationship?

My use case is eventually an aggregate, like 'count of the last 10 posts that are unpublished'. Was thinking I could get something working if I set up a relationship that was 'most recent 10 posts', and then an aggregate count on that relationship, but not seeing anything on how that'd work. Any ideas?...
Solution:
Yeah, that would work. You could also see what happens if you do this: ```elixir has_many :last_ten... do read_action :an_action_with_a_limit...

Test Question

Testing AnswerOverflow
Solution:
Here is an answer.

error with keyset pagination and random sort

As the title says i'm trying to define an action that should list my posts in a random sort while using the keyset pagination. This is the action that im calling ```elixir read :list do...

Simple policy checks based with relationships

Hello, friends! So on the website documentation, we have an example of a simple policy check: ```elixir # we're inside of a module here...

How to define custom sort?

I'm trying to get started with Ash but I'm really struggling with the basics. I'm trying to do something like this: ```elixir defmodule MyResource do use Ash.Resource, data_layer: AshPostgres.DataLayer...

Please delete

Hi, I just posted this so the new user server introduction thingy goes away, thanks!