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 Union Calculations

I'm still wrapping my head around polymorphic relationships and was wondering why a calculation on one needs to return a %Ash.Union{}? E.g. ```...
Solution:
We don't check that calculation return values match their declaration (for performance reasons)

Ash for cli apps

I am very new to Ash. I am working in an existing Elixir app that is a cli tool (for now, but will evolve to several parts: web, api, etc). Is Ash suitable for this use case?

When to use Ash.Oban vs Ash.StateMachine

have a very simple pipeline that needs to be durable, i.e. automatic retry. I am porting a Python code that uses Temporal.io durable execution.
I am not sure if I have to use Oban or StateMachine, when is each more suitable?...
Solution:
in general combining ash_state_machine and ash_oban to trigger state transitions is one of my favorite combinations of Ash features out there

Primary key not guaranteed unique?

I configured a column on my resource with primary_key? true and noticed that I can insert multiple records with the same key. Is that intended behavior? I figured for a primary key I should not need to set up a separate identity.
Solution:
primary_key? true on multiple attributes creates a composite primary key

AshAuthentication and UserIdentity for Oauth / Scopes

I'm getting my head wrapped around the framework so I will ask some stupid questions, my apologies in advance. I want to use google oauth / refresh tokens to have access to a user's google account in order to provider them services. I currently have AshAuthentication set up with google oauth strategy and it's immediately working. I did some searching for how to access and to specify the scopes. I found some resources about UserIdentity but I'm struggling to learn more about how to implement it. I am still very much adapting to the mental model of the framework. But my question for you is.. what concept am I missing / why am I struggling to find resources to understand how to better implement UserIdentity. Of course my ignorance is 100% responsible for this. But I'm not currently seeing how I can learn these things on my own and I'd prefer not to bother you all every time I have a basic question....

Is it possible to work around AshAuthentication tokens with read only connection?

Hey everyone! ๐Ÿ‘‹ I'm working with Ash Authentication using Google OAuth and Magic Link strategies. Sometimes we want to test with production data, but we connect via a read-only database for safety. The problem is that Magic Link token generation requires writes, which obviously fails on the read-only connection....

how to config user_id inside PaperTrail

Hi, sorry. based on this doc https://hexdocs.pm/ash_paper_trail/getting-started-with-ash-paper-trail.html#associating-versions-with-actors i configured my resource like these code, but when i see the user_id in Version with Ash.read all of them is nil ```elixir paper_trail do primary_key_type :uuid_v7...

Attempted to update stale record error update record in a loop

I think it is from ecto and i miss something, i do not want to use Ash generator here! so with a sleep it returns error ``` ** (Ash.Error.Invalid) Bread Crumbs:
Error returned from: MishkaCms.Runtime.Layout.update...
Solution:
I wrapped it inside, i think it fixed my code ๐Ÿง‘โ€๐Ÿ’ป ``` Ash.DataLayer.transaction(MishkaCms.Runtime.Layout, fn -> .... end)...

Extending a spark extension?

I'm working with ash_graphql. The codebase I'm working in has a bunch of old non-ash JSON:API routes. There's a part of the application that decides whether or not to send requests to the DB read replica or the writer, which for the old JSON:API stuff was wired up to go to the writer if it was a POST request, or also if it was in a list of ignored routes. For graphql this breaks down since everything comes through a POST, so I'm reworking how it decides to use the reader when it's an ash_graphql request. In general I can anchor on whether it's a query or mutation, however some queries will end up doing writes as well. So, I'm hoping to be able to have a simple way to just tack on an extra config to any query in the graphql queries block that allows marking that query as intended to use the writer. tl;dr, I'd like a way to add a new piece of config to the various queries config objects that some custom plug would be able to hook into. I swear I've seen some way to do this in docs somewhere but it's eluding me now ๐Ÿ˜…...

Load data works in terminal but in json api it returns empty

Inside this code i am trying to load all versions of a record for example, it works in my terminal and paper_trail_versions has some records as a list but in api json call the paper_trail_versions is [] empty ```elixir action :list_versions_api, :struct do constraints instance_of: MishkaCms.Runtime.Layout argument :layout_id, :uuid, allow_nil?: false...
Solution:
But you'd add a calculation like sorted_versions or something

Are there special requirements for returns :map in RPC actions?

Hi folks I have a custom action that works perfectly in the backend (logs show correct data) but AshTypescript RPC returns empty {} to the frontend. ```ex In Fmma.Inspections.Inspection resource...

Form validation message missing field name

Hey folks, I've just purchased the ash book and I'm just at the beginning. For some reason my form validation isn't showing any field names in the error message. I've done exactly as the book says, as far as I can tell, and I'm not sure if this is just how it's supposed to be. Any advice is very appreciated :) ```elixir...
Solution:
that's how it is supposed to be, as shown in the book ๐Ÿ™‚

When trying to set password using my own update I get Postgres type error in AshAuthentication

This boils down to that Postgres can't find the correct type for a parameter. Is that something I can take care of or is it somewhere else? <former gist-link, replaced by many messages below>...

Ash.Resource.Calculation with field_policy

in a calculation Ash.Resource.Calculation I have the following load: ```elixir def load(_query, _opt, _context),...

Problem with load of User

I my user, I have the following relationship ``` elixir has_many :organizations, CauseBeacon.Organizations.Organization do no_attributes? true...

Problem with Ash.Type.dump_to_native/2 after upgrade to 3.5.41

After upgrading to 3.5.41 my tests fail when there is a "NOT IN" query, apparently where before dump_to_native cas called with the atom (:cancelled) now a string "cancelled" is used causing the postgres query to fail. This is my custom type: ``` defmodule Admin.Resources.Types.TimerStatus do...

How to load archived resources?

I need to have resource data available in other resource listings even if they're archived. Currently, they're being filtered out. How can I configure them properly for these use cases?
Solution:
if so you can configure a read actions that don't apply the filter using https://hexdocs.pm/ash_archival/dsl-asharchival-resource.html#archive-exclude_read_actions and configure the read action on the relationship e.g. with https://hexdocs.pm/ash/dsl-ash-resource.html#relationships-has_one-read_action

No actor in after_action context

I wondering what is the correct or recommended way of passing the actor down to a after_change callback. I've tried to use the context but the actor was always nil. I've ended up doing this: ```elixir actions do defaults [:read, :destroy]...

mix ash.codegen not detecting changes

I have just created a new project, added two resources to a new domain with mix ash.gen.resource, and mix ash.codegen is says No changes detected, so no migrations or snapshots have been created. I am also getting a strange compiler warning about redefined modules, which makes me suspect something has gone wrong with the generators.
โฏ mix ash.gen.domain ChocolateMusicPlayer.Collection; mix ash.gen.resource ChocolateMusicPlayer.Collection.Track --default-actions read,create --uuid-primary-key id --attribute length:integer:public --attribute number:integer:public --attribute position:integer:public --attribute title:string:public; mix ash.gen.resource ChocolateMusicPlayer.Collection.Release --default-actions read,create --uuid-primary-key id --attribute date:date:public --attribute title:string:public --relationship has_many:tracks:ChocolateMusicPlayer.Collection.Track
โฏ mix ash.gen.domain ChocolateMusicPlayer.Collection; mix ash.gen.resource ChocolateMusicPlayer.Collection.Track --default-actions read,create --uuid-primary-key id --attribute length:integer:public --attribute number:integer:public --attribute position:integer:public --attribute title:string:public; mix ash.gen.resource ChocolateMusicPlayer.Collection.Release --default-actions read,create --uuid-primary-key id --attribute date:date:public --attribute title:string:public --relationship has_many:tracks:ChocolateMusicPlayer.Collection.Track
Diffs look fine. I accept each Proceed with changes? prompt....
Solution:
do you have AshPostgres.DataLayer in your resources? you probably need to add --extend postgres

`on_conflict: :nothing` for a create action

Is there a way to set something like on_conflict: :nothing for a create action? I've added this to my action, but IMO it looks weird: ```elixir...