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

Having some trouble with a bulk update

I have something like: ```elixir update :backfill_code do change fn changeset, context ->...
Solution:
I just pushed a fix to setting batch_size to main

Add value to manage_relationship input from current resource

I have this resource ```ex defmodule Aldente.Management.Invitation do use Ash.Resource, domain: Aldente.Management,...

AshGraphQL bulk upsert

I wanted to expose a bulk action on graphql, and there are no available options in create macro, My main concern is argument type generation, if not for that, I could write a custom handler, Is there a better way to handle this?
Solution:
Currently there is no builtin way

manage_relationship: Get changes in related records

My Invoice resource has many Items. Every item calculates its total in a change. I want to calculate the sum of those totals in the invoice but cannot find a way to read the full items, only the input. How can I do this? ```elixir argument :items, {:array, :map}, allow_nil?: false change manage_relationship(:items, type: :create)...

Reactor persistence and user tasks

I have a fairly involved saga I want to implement that I have currently as adhoc liveviews but that I want to make a bit more robust. Reactor seems fairly good for this (although I don't really need rollbacks). This saga includes both automated tasks (call some APIs, generate some data) and user-led steps, where the user has to interact with some stuff. Is this something that reactor would be good for? Would you create a model that stores the current step in the DB and then restarts from the nex...

Having trouble getting started with Ash

Hello, On Reddit yesterday I mentioned getting stuck with the startup with the Ash framework, I have gotten different issues different times but this was my most recent one I used the Ash websites code recommendation to get started, all I did was run the curl command which downloaded everything then I entered the directory it created and just running the igniter install commands fail...
No description

How to model context based multitenancy?

What would be the best approach to load the tenant info into the user when working with context base multitenancy? - If I use global? true I can log in without knowing the tenant, but I'm not sure what the best strategy to fetch the tenant into after - or during - sign in, given the current_user has no tenant data - If I use global? false I need the tenant info before sign in, which can be work. I just need to figure it out how to build the magic link with the tenant subdomain - probably a phoenix question though. Should I define my user resource as?...
Solution:
Yes you should likely do that 🙂

inline `type()` doesnt work. when defined as calculation on resource it works.

i have a really weird issue and i have no idea whats happening: ``ex # this works, where :id_as_string` is the calculation: expr(type(:id, :string)) authorize_if expr(^actor([:service, :id_as_string]) in addressed_groups)...

Phoenix 1.18 Ash authentication error

I'm seeing the following error when I try to access /sign-in or /register on a new application I'm playing with. `` [error] ** (RuntimeError) Cannot set assign current_user before default AshAuthentication.Phoenix.LiveSession.on_mount/4` has run. (ash_authentication_phoenix 2.7.0) lib/ash_authentication_phoenix/live_session.ex:163: anonymous fn/5 in AshAuthentication.Phoenix.LiveSession.on_mount/4...

ash json api - update by other field

```elixir json_api do type "tasks" routes do...

manage_relationship to create another resource `belongs_to` relation

Hi, I noticed I have a pretty common thing to define an action on a resource, which will automatically created related resources that is in the scope of the action. I wanted to know how to do that declaratively Example. ``` Organization (has_many Member)...
Solution:
manage_relationship will eventually call a create/update action etc., and you are providing inputs for it here

Using seed and changeset generators with child resources

I have a Child resource that belongs_to a Parent. I'd like to use the seed and changeset generators with these resources in my tests. I'd like to - generate the Child along with a unique Parent in one generator call - child = generate(child_seed()) - child = generate(child_changeset())...

Bulk update through AshAdmin is skipping 200 records, not sure why

I have a bulk action wired up like this: ```elixir update :backfillcode do change fn changeset, ->...

Calculation just ids from a relation

i need a calculation of just the ids from a relation (references to other table) here my experiment ```...

AshPaperTrail

`` [warning] Unhandled error in form submission for AshTableVue.GoldenDataset.Resources.Question.update This error was unhandled because Ash.Error.Framework.MustBeAtomic does not implement the AshPhoenix.FormData.Error` protocol. ...

Reactor and webhook

I'm trying out reactor, specifically for a payment flow. Before it, using stripity stripe, I created a session Stripe.Checkout.Session.create, redirected external session url. Then there's a webhook controller that constructs an event Stripe.Webhook.construct_event. how would that work using reactor flow? :thinkies: I'm guessing capture payment step should handle the webhook part, but I'm not understanding how would I plug the two? Is this even a valid use case for reactor 😬...
Solution:
You could have a resource that you call actions on that runs the reactor and saves the state after it halted and than have an update action that you can call that than runs the next part of the reactor with the saved state. and use the session id as the id for the resource

AshJsonAPI generic action arguments in a GET route

I have this simple generic action and route ```elixir base_route "/operational-settings", Core.OperationalSetting do route(:get, "/:configuration_key", :get) end...
Solution:
there is a query_params option IIRC that determines which action inputs are lifted to query params though

Calculation referencing a resource in a different schema

I'm attempting to do a ST_Union on a related resource, but that resource is stored in a different schema
calculate :geom, :geometry, expr(fragment("ST_UNION(?)", lgas.geog))
calculate :geom, :geometry, expr(fragment("ST_UNION(?)", lgas.geog))
...

How to manage notifications

I am trying to understand how to listen to notifications emitted from my resource actions and pass it down to a React client using Channels. Currently this is what I've got: ```elixir note.ex (resource)...
Solution:
Okay, figured it out thanks to the realworld-phoenix-inertia-react project. Turns out I shouldn't have created a channel to connect from my client with the same topic the resources emit the events to. They should be different — that's what was causing the weird behavior and the "ghost" and uncontrolled sending of data through my channel. Now my action is publishing to the topic notes instead of workspace...

Exist the postgres functions array on Ash queries

To be specific, i need check if a list exist in another list, i can use a calculation and use fragments, but dont know if i can be used directly from Ash.Filter like eq or not_eq ``` anyarray <@ anyarray → boolean ...