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

`AshJsonApi` composite primary key

Would like to add AshJsonApi to a project currently using AshGraphql, getting complaints about my many_to_many resources:
json_api -> primary_key:
AshJsonApi requires primary key when a resource has a composite key
json_api -> primary_key:
AshJsonApi requires primary key when a resource has a composite key
...

Auto forms silently drops some associations

I ran into this while trying to use auto forms, grabbing values from the created _join form. There were no errors, but not all of the resource associations were present. Looks like here https://github.com/ash-project/ash_phoenix/blob/main/lib/ash_phoenix/form/auto.ex#L469 we use Enum.find, so we are only getting the first occurence of the association. I tried editing it to Enum.filterand changing the type from :single to :list. This made the associations properly appear in the form, but submitting it failed. Got me wondering a few things. First, maybe I screwed up somewhere before 😅 . Secondly for fixing it if it is a bug, it doesn't seem like we can know :single or :list beforehand , so would we need to use an anonymous function to resolve which similar to how data is resolved?
type: :single,
data: &get_join(&1, &2, relationship),
type: :single,
data: &get_join(&1, &2, relationship),
Alternatively, is it possible to just make them all :list and handle the length = 1 case for single?...

Embed `has_one` relationship into resource

Let's say I have a resource A. It has relationship: ```elixir relationships do has_many :a_version, Ash.Api.AVersion do...

Resource interactions

So my simple question is this, how/can one resource interact with another. I have a "bank_account" and bank accounts can have "transactions" when a transaction is pending=false, which is set through the update :cleared action, I want to then add or subtract the amount on that transaction from the bank_account balance. See pseudo code in image attached for what I am envisioning....
No description

Serialized access to instance of resource for `AshPostgres`

Pursuant to the discussion in #general , I'd like to create a macro which uses the changes hook to ensure that change actions to an instance (row) of a resource are serialized. For now I'm only looking at Postgres support, but if the lock primitive comes into play, happy to update. Primary changes are the addition of a definitely-not-working locking statement and or changeset.type == :read to not block read actions. ```elixir defmodule AshPostgresUtil.SerializedChanges do defmacro using(opts \ []) do...

Using manage_relationship with nested relationships

I have three resource modules: ```elixir defmodule Patient do use Ash.Resource, data_layer: AshPostgres.DataLayer...

Does ash support multi tenancy with foreign key?

I search whole document but there is no place that mention multi tenancy with foreign key. Something like this in Ecto: https://hexdocs.pm/ecto/multi-tenancy-with-foreign-keys.html

Loading related resource, filtered using a property on the Join Table

https://hexdocs.pm/ash/relationships.html#more-complex-data-loading Looking here I see I can specify a query for the loaded resource which is sweet. What I'm wondering is if we have some metadata about the relationship present on the join table, what is the right/ash way to filter the loaded tables? A contrived example would be check User A's relationship to other users, filtered on created_date or some enum. Specifically for many_to_many, though I assume the answer would apply for all...

Help with contains case insensitive Query

Hi I'm pretty new to elixir and ash. I'm trying to do a search by title. However I don't know how to make it case insensitive. I saw the Ash contains functions but it uses Ash.CiString. And I'm not sure how to use it.
this is my code read :by_title do...

`is_a` relationship type

It would be great to have an is_a relationship, meaning each row in the source resource matches one and exactly one row in the destination resource, and has a matching primary key. Perhaps there is already an idiom for this?

Getting Started with Ash and Phoenix Blog question

In the ash_phoenix tutorial where it talks about creating the Registry, shouldn't

entry MyAshPhoenixApp.Blog.Post

entry MyAshPhoenixApp.Blog.Post
be...

Idiomatic way to create attribute-specific policies

I'd like to create policies that describe which attributes an actor is allowed to CRUD, based on their attributes and other data in the model. Is there a way to do this without regard to the named action that is performing the operation? For example, I would like the attributes available for an employee record to differ based on whether the actor is themselves, an HR rep, a manager, their manager, etc. and have these policies enforced across all actions that touch those attributes. Ideally, this would also be enforced transparently in the case that the attributes being requested are not explicitly specified. For example, if a user performs a bare read, they should simply get all—and only—the attributes that they have access to without error. If a user specifically requests a set of attributes containing a subset to which they do not have access, this should error out....

Filter function do not work...What am I missing? (Returns empty)

```elixir defmodule Ampldev.Syllabuses.GySeCourse do # This turns this module into a resource use Ash.Resource, data_layer: Ash.DataLayer.Ets...

Using `Ash.Type.String` like `Ash.Type.Enum`

What I'm imagining: lib/bookstore/types/isbn.ex: ```elixir defmodule Bookstore.Type.ISBN do...

Cache layer to Ash rest api

Hi How could we add the cache layers tot he Ash rest api end points. Any suggestions. -Sriky...

Using args in policies

I'm trying to figure out how to use args in my policy as I've seen in the documentation but all I ever get back is nil. Any help would be appreciated. Here is my code. How does one get the attributes to use in your policies? I see in the docs something like ^arg(:attribute_name) but doing so is not working for me. This is my resource. ```defmodule OpenBudget.Budgets.Transaction do use Ash.Resource, data_layer: AshPostgres.DataLayer, authorizers: [Ash.Policy.Authorizer]...
No description

Exdocs for Ash rest api

Hi Is there a recommended way to document the JsonApi in Ash. Should we use the ex_docs, where the end points are declared. Or are there any other recommendations. -Sriky...

Multitenancy and different Liveviews

So this might not be directly related to AshAuthentication, but somebody could help me figure out what's going. I'm still super new to Elixir and Phoenix so bear with me haha Continuing from the discussion above with multitenancy...

Passing validation arguments for the Form's underlying actions

How do I pass arguments in this line? I can't seem to find an example in the docs. AshPhoenix.Form.validate(socket.assigns.form, params) If action :create requires user_id as an argument, is it simply passed by including it in the params? like %{user_id: "12345"}...

AshPhoenix.Form doesn't seem to respect phx-feedback-for

I noticed that my forms will always return all errors for all fields as soon as I call validate, even if I add the phx-feedback-for binding. Is that expected or do I need to add some option to change that? I couldn't find anything about this in the docs....