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

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

Igniter messes with sourceror

I have a pretty empty Phoenix 1.8 project where I have added igniter, ash and ash_phoenix, using igniter, without issue. Now I want to add ash_authentication with mix igniter.install ash_authentication --auth-strategy magic_link, however that fails after setting up igniter with: ```...

How to show embedded resource in Ash Admin

I want to create some actions on an embedded resource that I want to call from the Admin UI. Is that possible?

Is there a guide for bringing Ash into an existing phx.gen.auth app?

I've seen a few posts about this in the past but nothing recently. It may be as simple as creating a User resource that matches the Ecto schema and turning automatic migrations off? But then how do I get current_user into the scope/context so that all of the policy stuff works great? Trying to gauge if it's more effort to attempt this or to replace all of the auth (including UI) with AshAuthenticationPhoenix.

Manually sign in a user in Phoenix

I have a homegrown invitation solution where admin users can invite other users. I did an experiment with using the magic link strategy, but my thinking is that I don't want to actually create the user record until the invitation is accepted. The following Phoenix controller handles accepting an invitation: ```elixir defmodule DrengWeb.InvitationController do...
Solution:
This might a bit dirty, but by adding the GenerateTokenChange and borrowing the magic link signin strategy I got my action to work ```diff create :sign_up_with_invitation do argument :token, :string, allow_nil?: false ...

Deeply nested forms

Hi all, you know how Ash supports nested forms? Is there a way to do doubly or triply nested forms? Or is there a different approach to achieve this if this is not natively supported?
Solution:
I think it should be possible, looking at the code, the forms option has another forms field, so you should be able to nest them that way.

Question on Multitenancy.

I read this doc But few things are not still clear for me. I am trying to add Attribute Multitenancy 1. Should I add multitenancy macro and belongs to :organization to all resources? 2. I noticed we have functions like Ash.Query.set_tenant for read and Ash.Changeset.set_tenant for create. So I don't need to add something like change manage_relationship(:organization_id, :organization, type: :append) for create action?...

How to pass `opts` to Repo module functions?

Example:
opts = [settings: [final: 1]]
Repo.get(User, id, opts)
opts = [settings: [final: 1]]
Repo.get(User, id, opts)
Can it be passed through resource actions?...

Adding new create action produces error in resource schema

I have two resources in the same domain, Container, Image and ImageCredentials. Container has a belongs_to relationship with Image, Image has a has_many relationship with Container and a belongs_to relationship with ImageCredentials, while this last one has a has_many relationship with it. Container has a create action (:create_with_nested), with the purpose of creating a new Image in case of a failed match or lookup. I'm fairly new to Ash, and I tried to add the same logic to Image if it cannot match or lookup a ImageCredentials by adding the following :create_with_nested action to Image: ```ex create :create_with_nested do...