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

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...

AshOban - no configuration for `domain`

I'm trying to get a scan to run on a cron schedule with Oban, but I'm having some trouble configuring it. This is my Oban configuration in the resource: ```elixir defmodule App.Compliance.ScanConfiguration do...
Solution:
you can tray and add ```elixir oban do...

Bypassing tenancy & authorization to load related data in special read

Th following action reads the received invitation of a user to join the establishment of an organization (both are tenants, org being the top tenant). ```elixir read :get_received_invitation do multitenancy :bypass...
Solution:
:bypass_all IIRC

get_and_lock_for_update missing data

Hello! I have an action that does a get_and_lock_for_update, then does an anonymous function change. It does this in order to do an array append into an {:array, :map} field. ```elixir...

Adding new changeset arguments in `before_action`

Hi, I'm having a bit of trouble understanding the order in which changes get executed within an update action and how to set arguments. Suppose I have something like: ```elixir update :foo do require_atomic? false...

Best option to read a relationship which has policy in Action

Hi, I so much searching today and with AI to be allowed load a relations in action, but i think there is better way! for example in user resource get_by_subject I added this: ```elixir read :get_by_subject do...
Solution:
Finally i found :)) i created this debugger 😂 😂😂 ```elixir defmodule MishkaCms.Accounts.Checks.DebugAccessingFrom do use Ash.Policy.SimpleCheck ...

Aggregate first() generates seemingly inefficient subquery

The following code ```calculate :cover_image_path, :string, expr( cover_image.path || first(photos, field: :path, query: [sort: [inserted_at: :asc]])...

Show live changes depending on nested data

I have an Invoice resource that has_many InvoiceItems. Every InvoiceItem gets some data (quantity, tax_rate, unit_price) and calculates the item's total amounts in a change. ```elixir Invoice Resource change manage_relationship(:items, type: :create)...
Solution:
I couldn't really find out how to use transform_params here. As far as I can understand it's helpful for updating the parameters that get passed to the form, but my "calculated" fields are not actually part of the form. I was able to figure out another way – maybe it's helpful for someone else, so I'll share it. The solution was quite easy: 1) Run the necessary calculations in the top level changeset (also):...

How to implement multi tenancy in user with unique email per site and global

Hi, sorry. I need to have an email global and email which is assigned to a site in my system For example: ``` email1@g.com no-site email1@g.com site1...
Solution:
It is automatically added by virtue of being the multitenancy attribute

Subscriptions return all data regardless of tenant

I am running into an issue where all data is returned by a subscription even when multi-tenancy is set up. I have a product resource that belongs to an organization. The tenant attribute is the organization_id on the product. When creating a product, all subscribers receive the data including for products outside their tenant. ```elixir...

Following the guide in AshAi

I get this error when I am trying to use the cosine distance between the vector and the embedded question, I have the same code as the guide
function: :vector_cosine_distance, arity: nil, resource: Taleed.Poetry.Verse, could_be_calculation?: false, splode: Ash.Error, bread_crumbs: [\"Error returned from: Taleed.Poetry.Verse.vector_search\"], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :invalid}" while retrieving Exception.message/1 for %Ash.Error.Query.NoSuchFunction{function: :vector_cosine_distance, arity: nil, resource: Taleed.Poetry.Verse, could_be_calculation?: false, splode: Ash.Error
function: :vector_cosine_distance, arity: nil, resource: Taleed.Poetry.Verse, could_be_calculation?: false, splode: Ash.Error, bread_crumbs: [\"Error returned from: Taleed.Poetry.Verse.vector_search\"], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :invalid}" while retrieving Exception.message/1 for %Ash.Error.Query.NoSuchFunction{function: :vector_cosine_distance, arity: nil, resource: Taleed.Poetry.Verse, could_be_calculation?: false, splode: Ash.Error
...

Inconsistent behaviour between Ash.get and read actions, and Ash.load in context multitenancy (pg)

Ash.load(resource,[...], actor: user, tenant: company_id) works Ash.get(resource, actor: user, tenant: company_id, load: [....]) doesnt work, same with custom read actions on resource Is there some limitations with the context mulitenancy that i should be aware of? because i have struggled quite alot just loading relationships on resources, which should be one of the simplest things, but its not. I get wierd errors when i load with Ash.get or using custom read actions that there is not table like <UUID>.my_resource_table. It almost feels like it hits the wrong Repo or the wrong database. Im using two repos, but i just commented out the other repo from config and tried again, same error. this is the error i get ...
Solution:
@Zach Daniel ill mark it as solved, i dont have time to debug why it failed in the old project. Its working in the new project now.

Many to many relationships and join tables in ash admin.

I am wondering if there is a way to configure the tenants section of the register with password form in ash admin to show the same drop down that is shown in the create form for the user-tenant join table. This would be a big quality of life upgrade for some of my less technical users.
No description