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

Accept subset of Ash.Type.Enum in action

I have an Ash.Type.Enum defined as ```elixir defmodule Dreng.Accounts.Role do use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand] end...
Solution:

Update Params in Nested Form with Union type

I have a code snippet that looks as follows: ```elixir def update_subform_field(root_form, subform_name, new_value) do AshPhoenix.Form.update_form(root_form, subform_name, fn sub_form ->...

Ash.Error.Unknown.UnknownError: Invalid reference

I have this action in the UserUpload resource. I added another criteria for filtering the resource by the first or last name of its user relationship. However, the String.contains? lines give this error:
11:29:38.679 request_id=GFIrFgeBN9WstPIAASCB remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Unknown{errors: [%Ash.Error.Unknown.UnknownError{error: "Invalid reference user.first_name at relationship_path [:user]", field: nil, value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :unknown}]}}
11:29:38.679 request_id=GFIrFgeBN9WstPIAASCB remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Unknown{errors: [%Ash.Error.Unknown.UnknownError{error: "Invalid reference user.first_name at relationship_path [:user]", field: nil, value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :unknown}]}}
The relationship and its first_name and last_name fields are public?: true...
No description

Advise on using policies with related resources

I have two resources Transfer and Account. Transfer updates the accounts balance it's related to. Now I have admin which can create/update/read both resources. I have an operator that can only create transfers. The issue is updating the account balance when the operator creates the transfer. Since he does not have access to create/update an acccount....

AshCommanded - I'm running in to an issue with ash_commanded not working with spark v3?

Heyo! Long time follower, but first time poster. I'm just kind of curious about the ash_commanded project and if anyone is using it? It seems like it might be dead which is surprising to me considering how popular commanded project seems to be....

How to set the actor within an action

Hey everyone! Currently, we have an action that takes a user as an argument: ``` create :upsert_meeting_prep_action do...

Subscriptions do not work when declared in the domain.

Subscriptions work when declared in the Resource like this: ```elixir defmodule JoseValimIsMyHero.Accounts.User do use Ash.Resource,...

Plug.CSRFProtection.InvalidCSRFTokenError

Is there some documentation I can refer to about handling CSRF error for email confirmation using Ash Authentication. Clicking on the Confirm button on the confirmation email gets me this error. Plug.CSRFProtection.InvalidCSRFTokenError at POST /auth/user/confirm invalid CSRF (Cross Site Request Forgery) token, please make sure that: ...

Rollback went further than expected

Did I do this incorrectly? I ran mix ash.rollback -r Ngen.Repo and answered the prompt but it rolled much further back than I expected. ```bash How many migrations should be rolled back? (default: 0) ...

Persisting values from relationships at creation time

Hi there! I'm working on a demo that allows products to be purchased by users. Since prices might change over time, I'd like to put the price of the product at the time of purchase into the order resource record. Given a product with the following attributes...
Solution:
``` change before_action(fn changeset, context -> product_id = Ash.Changeset.get_attribute(changeset, :product_id) product = AppName.DomainName.get_product!(product_id, actor: context.actor) ...

Does `AshPostgres` support partitions? i.e. Schema-based multitenancy

I checked the docs, but didn't see any reference to partitions. When you use `global? True for schema-based multitenancy, what happens? 1. The global table is partitioned, and then use the tenant partitions for the query? ...
Solution:
It creates a global table allowing you to have both tenanted and non tenanted data

How to add authorization to filter nested data

I'm running a graphql query with the following filter ``` { teams: { id: {...

Multiple Tenant Resources

In my app, I have two tenant resources: Organization and Establishment. I'm using the new scope feature and the value for current_tenant is a map containing both tenants. I need to provide an Ash.ToTenant implementation that extracts the correct tenant depending on the resource being queried. I've tried this: ```elixir...

Ash.Reactor - Transform results for `initial` or `argument`

I'm calling an API and then creating records from the response. Is there a way to transform the API result into the record attrs in the create or bulk_create step? Or is it better to have a separate transform step and use its result as the initial for create or bulk_create step? API Call step -> Transform Results to Resource attrs -> Create or Bulk Create step...
Solution:
I think you'd want to do a separate step

Is it possible to list and select the relationship in the Admin resource creation form?

For example: I'd like to list all registered users and select one to associate with the Pet I'm creating. Is there something ready to do this?
No description

ash notifier pubsub question

I've got a scenario where pub sub from one resource works, and then another resource where it does not. in the live view we're subscribed and handling: ```elixir...

JSON API raw response

I have a json API route to an action that returns a raw binary which is already gzipped in advance with :zlib.gzip(). But Ash JSON API tries to encode it with Jason and raises an error. How do I tell it to return the raw response as is?...

AshPhoenixForm not executing action on submit

Hey, i'm not sure why but when i submit a form for my update action it is not executing any update query ```elixir form = AshPhoenix.Form.for_update(data, :update, actor: actor) |> to_form() .... def handle_event("save", params, socket) do...
Solution:
shouldnt it be like this? ``` def handle_event("save", %{"form" => form_data}, socket) do case AshPhoenix.Form.submit(socket.assigns.form,...

Understanding indexes

I come from the Node.js/MongoDB world and I'm learning Elixir and Ash. I'm trying to ensure my resources/tables are correctly indexed (using AshPostgres). For that I have the following questions when using Ash: 1. Is the primary :id attribute always indexed? 2. If one would like to make a partial index like [:user_id, :is_active] we should use custom_indexes inside the postgres definition, right? - would this then also be usable by queries that only filter on :user_id (but not filtering on the :is_active )?...
Solution:
1. In Postgres at least, yes. Primary keys get a unique index. 2. This is more of a Postgres question than an ash question, I'd suggest looking at their docs. IIRC you're describing a composite index not a partial one (a partial one would be one with a where clause). 3. Yes. The identities have other uses but they imply a unique constraint and the migration generator will create one 4. Yes, that is how you'd do it 🙂...