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

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

How to handle submit-only actions without data layer but with validations?

Hi everyone, I'm just getting started with Ash and ran into a challenge when trying to build a LiveView form that validates input and then sends the data to an external API, without using a data_layer. I'm using a create action with validates and a change/3 callback for the external logic. The issue is: change/3 is called before validations are applied, and changeset.valid? is already true, so my logic executes even when the input is invalid. Since I'm not using a data_layer, before_action and after_action hooks are not triggered — which would have been ideal for running the API call only after validation....

map datatype type form with ash_phoenix.gen.live

attribute :data, :map do public? true end when creating a new element of this resource I had to leave data blank inserting JSON in the browser was not possible...

Actor attribute in relationship filter expression is NULL

I have an Actor Resource that has a project_id attribute and it has been used successfully in policies many times. But for some reason in this relationship it is always NULL: ```elixir...
Solution:
Can I see the code where you're doing that? Are you specifying the actor theere?

destroy action based on filters

I currently have a read action and I pass the result to the default destroy action, is it possible to have a destroy action which includes the read part? It seems like destroy only works when passing along the objects So basically I want to destroy the results of ```elixir...
Solution:
okay so you want to call it via a code interface. you can add the option require_reference?: false to the code interface, and then provide your own filters etc. in the action. (make sure to specify filters or it will delete everything)

manage_relationship does not insert

```ex create :register do accept [:name] argument :members, {:array, :map}, public?: false, default: [] ...

Policies for `create` upsert actions

I have a create do upsert? true end type of action that I'd like to put a policy on. However, I get a warning that says I can't add policies to create actions, basically because the data doesn't exist yet to be able to authorize against. So this is a two part question. Question 1: When upserting, there is data. Is there a way to authorize that? Maybe I'm relying too heavily on upserts. ...
Solution:
You can make it an update action on Site