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

Forgotten `change` in update action leads to hours of troubleshooting and sadness

I forgot a change in front of a set_attribute in an update action and nothing really reacted to that except that the attribute wasn't set. Is there a flag I can set somewhere to have Spark or Ash or something crash loudly at me when I use keywords in wrong places? Sad code: ```elixir update :set_family do...

Server-side params for AshPhoenix Form

Sometimes I will have an AshPhoenix form to create or update a resource, and I want some of the fields to be provided from the server and not set or visible on the client. Sometimes these are coming from uploads, other times it's computed from other state. What is the best way to provide this data to validate and submit? So far I've been defining a form_params(socket, params) helper that injects/overrides various params before passing the result to validate/submit. This has worked OK but feels wrong, and today I ran into an issue of having to reverse-engineer how AshPhoenix expects unions to work. Appreciate any insight and guidance y'all can provide!...

Claim tenant did not pass validation in multitenancy

Hi, i have multi tendency in my project which let user no tendency or based on his host and put it inside plug For example ```elixir def call(conn, opts) do...
Solution:
Thank you there were some problems in my custom plug 🫄 🚬

Miss understanding to use policy in read action, Handling Missing Actor

Hi sorry again, I've read the documentation multiple times but still struggle to properly handle a case in my :me action. Here’s my current setup: ```elixir...
Solution:
Oh i changed my order of policies it shows :thinkies: 🥲 this was the last line of policies and i move ```elixir bypass always() do...

ashai vectorize

There is an issue where the code keeps embedding vectors even though they were already embedded I am on postgres 16, ``` sudo -u postgres psql -d t_db -c "select count(*) from poems;" count -------...
No description

Ash Authentication ApiKey strategy

How is the correct way to create a ApiKey to be used for users. https://gist.github.com/phsacramento/ad22e42fb4c357d99b694fb8ed511b52 On this example, i'm not able to get generated ApiKey using Api's request....

AshJsonApi.Test post function does not allow change host

Hi, sorry, I think the AshJsonApi.Test post function dose not allow to overwrite the host as a header, is it bug? or i am writing host in bad place? like: ```elixir headers = [{"x-no-tenant", "false"}, {"host", "test.example.com"}] url = "/auth/sign-in#{filds}"...
Solution:
You can pass a tenant option

ash resource force load relationship

How can I force load a relationship, I tried adding Ash.Query.Load in my action but it doesn't take effect.

Prefix changes the Api path in SwaggerUi but Not Acceptable

Hi sorry, I set prefix "/api/v1" in my json_api and it is changed inside SwaggerUi to this prefix. For example /api/v1/auth/sign-in like this ```elixir json_api do prefix "/api/v1"...
Solution:
Just change the route that you serve the api at in your router

Bypassing Multitenancy on Destroy Actions

My goal is to delete any invitation that is expired using a cron job (Oban) ```elixir destroy :delete_expired_invitation do multitenancy :bypass filter expr(expires_at <= now())...
Solution:
This is working though ```elixir MyApp.Establishments.Invitation |> Ash.Query.for_read(:expired)...

Anonymous users with AshAuthentication

Context As a part of the app I'm currently building, there will be anonymous users as well as "authenticated" users that log in with email and password or other strategies. Authenticated users will create entities that can be shared through generating a public link. Anyone with the link will be able to view and comment on the entity created by the authenticated user. However, the comments still need to be tied to a user because only they should be able to do things like delete or edit sent comments. Question Does anyone have a recommended way to handle anonymous users? ...

Managing Relationships - Cascading deletes for has_one relationships.

I'm trying to work through setting up relationships the Ash-way and here's roughly the structure I have: * A Campaign Has One Ship Has One Stash ** Has Many Crew Members...

Completely delete a resource

Hi everyone. If I fully want to delete a resource (tables and everything). What do I need to do? Do I just delete every mention of it in my code (it's resource module, code interfaces etc) and run codegen? Or is there a different way? Thank you
Solution:
You can do as you described, but then do mix ecto.gen.migration and add the ecto code there to drop the migration

Can not access to actor from token in create action

Hi sorry, I think I might be making a silly mistake somewhere. As you can see, I don’t have access to the actor in the create action — it’s always nil. However, I don’t have this issue in the read action, where I can access the actor without any problems. ```elixir create :register_with_password do description "Register a new user with a email and password."...
Solution:
i think i found it i am deleting it in my custom plug

Ash Paper Trail, changes

Hi, I am currently useing ash_paper_trail on a ressource that have an attribute define as :map. inside this map there is nested maps too. ...

How can show calculate as fields object in Swaggerui

Hi sorry, i made my calculate public and i can see in the example of Success Responses but inside fields object it just shows the attributes! and user has to change it by his hand and add the calculate name . if i change this manually in the fields object text aria it works! Is there a way to show calculate as fields inside this text aria as default? or i should change the AshJsonApiRouter? Thank you in advance...
Solution:
But it does look like that open api schema is wrong. Issue/PR welcome 🙂
No description

Bypass all authorization for specific read action (including loaded relationships

I have this read action: ```elixir read :get_received_invitation do get_by :id multitenancy :bypass_all...
Solution:
I'd suggest using the accessing_from builtin check

Json API for `request_password_reset_token` auth

Hi, sorry; I'm trying to create an endpoint for request_password_reset_token so that the user can send a password reset request. But the issue I'm facing seems to be that the structure isn't compatible with what the JSON API expects, and as a result, it throws an error. I wanted to know if there's a way to do this at this stage without changing the action itself? ```elixir post :request_password_reset_token do route "/reset_request"...
Solution:
So you need to use route ...

Update action discrepancy

I have an update action: ``` update :retire do change set_attribute(:status, :retired) end...
Solution:
are you calling them the same way? eg. with a single record?

How to create an atomic validation for the amount on AshMoney?

I have an attribute using AshMoney like so: ```elixir attribute :amount, :money do constraints storage_type: :money_with_currency...