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

relationship data

Hello everyone! I'm trying to migrate the backend of an old ember app from rails/json-api-resources to Ash. The resources produced by rails contain relationship data even when not added in includes. I can't reproduce this with Ash, and would like to know if it's possible. ``` {...

many to many relationships management.

I couldnt find clear way but got it working. Eventually i got it working, but i would like to get some tips/tricks, if this they way, or am i missing something obvious? ```elixir Resource actions do...

Tips to speed up compile times?

As my resources have grown, my compile times have gotten irritatingly long. Any tips for improving them?
Solution:
```elixir defmodule Foo do use Ash.Resource.Change def change(changeset, opts, context) do...

Questions about Cinder

This is a really cool library and I've toyed around with it a little bit, but I do have a couple questions I was hoping someone could help out with. Are you able to do queries for the filters? For example, say we have a timestamp expired_at but we want a dropdown select the the options expired or active rather than a datetime range, is that possible? I couldn't quite figure out how to set the filter to say I want one to be the nil values and the other to be not is_nil(expired_at. And with calculations, can we have them as one of the columns? Say we have a full_name calculation that combines first_name and last_name. Can we just do user.full_name or would we need to explicitly load it to get it to work?...

Custom type not showing in Admin UI update form

I have a custom type that wraps %Duration{} with some custom logic for parsing it from a string then converting it back to a string. I've implemented the protocol Phoenix.HTML.Safe which just calls my function to return a string of the duration. My custom duration shows up in the primary read action of the Admin UI. It also shows up when I click the little circled into button on a row....

Union queries that return union types

I want to make a union query that will return a union type, which will be resolved with graphql. Could not find an example, and Combination queries seem to be for a different usecase. Can this be done with declarative syntax or do I need a separate custom query? thank you...
Solution:
combination queries don't support producing different resources

Bypassing multitenancy directly from code interfaces

I know there is the multitenancy :bypass option for read actions but is it possible to pass it as an option in code interfaces as well? Something like this or similar is what I'm looking for: ```elixir...

Ash.page resulting in ** (EXIT) no process: the process is not alive or there's no process currently

My paginated read query is failing with this error. This used to work fine, so I wonder if something changed with Ash. ``` 17:13:23.603 [error] GenServer #PID<0.2666.0> terminating ** (stop) exited in: GenServer.call(#PID<0.2670.0>, {:get_and_update, #Function<0.88285443/1 in Ash.Actions.Read.AsyncLimiter.async_or_inline/4>}, 5000)...

Loading multitenant resources

Given the following action: ```elixir read :list_organizations do prepare build(load: [:establishments]) end...
Solution:
```elixir read :list_organizations do prepare build(load: [:establishments]) multitenancy :bypass_all end...

How do I get `fragment` in scope in a `prepare` block?

I'm wanting to sort a query using a fragment. I found this https://elixirforum.com/t/how-do-i-sort-records-by-random-in-the-resource-action/58774 that looks like it would work. However, I get an error when I try. My code: ``` read :my_action do argument :embedding, :vector, allow_nil?: false ...

How to get tenant in LiveView after setting it using `PlugHelpers.set_tenant`

I'm currently setting my tenant in my controller like this:
conn
|> put_session(:tenant, tenant_id)
conn
|> put_session(:tenant, tenant_id)
...
Solution:
ok I think we are going in the right direction, so the authcontroller code is called when you sign in, but then it redirects and there you get a new conn and the browser pipeline only loads the user from the session. You need another plug/controller that you put after load_from_session, where you put this code ```elixir tenant = if user.is_super_admin? do...

install is not the latest version

mix archive.install hex igniter_new only install 0.5.29 instead of 0.6.10...

Translating Ash Error messages

What are my options for translating error messages returned by actions? The first thing that comes to mind is translating the errors in the controller like this: ```elixir...

Is it possible to convert policies expression to Ecto expressions?

Kinda of a weird request but I'm wondering if it's possible to resolve the policies expressions so I can reuse them in a regular Ecto query. I started with this code but I'm new to Ash and a bit lost here: ```...

Wrapping external API - get one object

Hey 👋 I'm starting to learn Ash and I'm trying to use Ash.Resource to wrap an API. Looking at the example at https://hexdocs.pm/ash/wrap-external-apis.html, I can see how I would do that for a paginated list endpoint. Now I'm trying to figure out how to do something similar that returns one object and not a list. The list example uses Stream.resource and Ash.Query.apply_to, so it's not clear to me how to proceed....
Solution:
Read actions return multiple results always

Help with multi-step resource creation in Ash (Phoenix + React)

I’m building a multi‑tenant app with this structure: user → organization → establishment → establishment_user In my flow, a user creates both an organization and an establishment, and the system automatically creates the establishment_user behind the scenes. ...
Solution:
1. after_action was the right choice, you can't set a different tenant with manage_relationship AFAIK 2. all run in the same transaction, the first action call opens the transaction and all the after action starts the next action in the same transaction 3 . all accessing_from is checking is a certain value in the context, so you could just manually set the context when calling the other actions inside after_action...

Using Pgvector and Ash.Vector

Greetings! I have a few Ecto schemas using Pgvector.Ecto.Type. I've been attempting to slowly move them over to Ash resources using the Ash.Type.Vector but I've been unable to get both extensions to coexist. I tried globally defining both: Pgvector.extensions() ++ [AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions() , but depending on that list order one or the other breaks. I also tried matching on type to get around it in a custom extension, which works for encoding: ```...

Version 3.5.25 generates wrong SQL

``` * ** (Postgrex.Error) ERROR 3F000 (invalid_schema_name) schema "excluded" does not exist query: INSERT INTO "tokens" AS t0 ("subject","purpose","created_at","expires_at","jti","updated_at") VALUES ($1,$2,$3,$4,$5,$6) ON CONFLICT ("jti") DO UPDATE SET "subject" = EXCLUDED.identifier('subject'), "purpose" = EXCLUDED.identifier('purpose'), "expires_at" = EXCLUDED.identifier('expires_at'), "updated_at" = COALESCE(EXCLUDED.identifier('updated_at'), $7) RETURNING "updated_at","created_at","extra_data","purpose","expires_at","subject","jti" ...
Solution:
updating only ecto causes this issue

Query across many tenants

I am developing an application with postgres attribute multitenancy and there is one query that I want to make across multiple tenants (tenants will be provided as argument) I was wandering if there is a way to do that somewhat simpler and more idiomatic, then just making a custom query and running a query multiple times. I also have nested fields to resolve for each element, so I would need to resolve every dependency somehow too....
Solution:
You can make specific read actions allow bypassing multitenancy with multitenancy :bypass

Ash.Actions.Read.AsyncLimiter - Process is not alive or there`s no process .....

Hi! I am at a loss here with trying to debug the origin of this error. Everything works when I perform a normal Ash.read, but as soon as I use Ash.page I get the following error....