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

Restricting aggregate calculations

I have an "aircraft" resource that has this aggregate: ```elixir sum :total_flight_hours_mins, :tech_logs, :airborne_time_mins do description "Total flight hours in minutes for this aircraft" end...
Solution:
```elixir calculate ..., expr(sum(tech_logs, field: :airborne_time_mins, query: [ filter: [expr(... ^arg(:foobar))] ])) do argument :foobar, ......

Pagination of primary action breaks showing relationships

I think I may have found a bug. I have resources A and B with a many_to_many relationship. I edited the primary read action of B to make it require pagination with required?: true. This is because I wanted to make it so that even if someone calls my API without a limit, the default limit per page is still applied. But now, when I go to A in the Admin UI, click on a row, then click the button to load its related Bs, nothing happens. No SQL query is executed. When I un-require the pagination, then it works. Yet, when I click the second button that only shows the IDs of the rows of the "join_through" resource, that one works....

Code interface vs domain resource block

I’ve read the docs a few times and I can’t tell whether code interfaces are recommended in Ash 3. I seem to remember that they are a vestige of previous versions but I don’t see any mention that they are deprecated or discouraged. Is there something that code interfaces can do that I can’t do in a domain resource block?
Solution:
I don't really use it as well. I mostly just think about them as functions

AshAuthentication custom strategy UI

I am trying to implement a custom strategy that verifies the user login with some custom rules, but after following this documentation i am stuck on where to implement the UI (https://hexdocs.pm/ash_authentication/custom-strategy.html) Is there any demo project that can serve as a reference for this? Do i just use UI Overrides? (https://hexdocs.pm/ash_authentication_phoenix/ui-overrides.html)...

n8n cannot access mcp client in Phoenix

Im running an MCP server in my Phoenix application. MCP Inspector says that everything is set up correctly. Now Im trying to access that MCP server locally from n8n using the MCP client node but it keeps saying that it could not connect. Phoenix returns the following error: (Phoenix.Router.NoRouteError) no route found for POST /%7B%22url%22:%22http:/localhost:4000/mcp%22%7D n8n seems to send a json object in the url In the MCP Client Node in the SSE Endpoint field I have provided http://localhost:4000/mcp ...

Can't disable derive_filter? in json API

I have this json API definition in my domain ```elixir json_api do routes do base_route "/runtime-config", MyApp.RuntimeConfig do...

Action-specific parameter sanitization

Is there a way to sanitize a random map of params that is used for a specific action? Here's my exact use case: - I have a map coming from query string params - That map may contain extra or invalid keys...
Solution:
When calling the action you can do skip_unknown_inputs: :*

AshJsonApi with InertiaJs

Is there a way to leverage AshJsonApi without... the api part? By that I mean the serializtion, public? attributes, etc.

code_interface, compile time vs runtime

if this were a code_interface, is timestamp captured once at compile time and all future calls use that compiled timestamp value? If yes, is there a different way to solve this? I've got multiple live views calls this code_interface and I'm wanting to keep all the logic in one place ```elixir define :get_budget_with_accounts, action: :read,...
Solution:
i.e default_options: fn -> ... end

Multitenancy with code interface on the domain?

So I have this: ```elixir defmodule MyApp.FlyingTrainingOrg do use Ash.Domain # ......
Solution:
There is a tenant option to all code interfaces 🙂

:datetime with constraints vs :utc_datetime_usec

Hey all, I’m looking at the docs for the different datetime options and they mention >A wrapper around :datetime for backwards compatibility https://hexdocs.pm/ash/Ash.Type.UtcDatetimeUsec.html...
Solution:
They are equivalent and will likely not change anytime soon. Someday we may warn when you use :utc_datetime_usec over the constraint.

For update form with params?

I'm wondering, when using for_update on an existing resource, do I need to explicitly make a params map? I was expecting it'd be auto populated. Even when I did Map.take/2 on the resource and put that as params it didn't work because params expect string keys. Am I missing something or is this expected? 🤔

after_action is not being triggered

I've tried several combinations, but it seems that the after_action callback is not being triggered. As a basic test, I added an IO.inspect expecting to see output in my IEx session, but nothing gets logged. Here's the code I'm using: ```elixir...

AAP and Phoenix.LiveDashboard

If I put live_dashboard inside my ash_authentication_live_session :admin_required router block, I get a compilation error about nested live sessions.
** (RuntimeError) attempting to define live_session :live_dashboard inside :admin_required.
live_session definitions cannot be nested.
** (RuntimeError) attempting to define live_session :live_dashboard inside :admin_required.
live_session definitions cannot be nested.
...

Unable to send a `Ash.Type.File` as argument to action using `AshPhoenix.Form`

When trying to send a Ash.Type.File struct as an argument to an update action, AshPhoenix.Form is failing on validation. Worth nothing that sending the file argument as :override_params in AshPhoenix.Form.submit does bypass this and work correctly, as does calling the action directly. AshAdmin also exhibits this behaviour. ...

Guidance on Generators

Need to implement a generator for a resource action that makes use of after_action hooks (organization > establishment > establishment_user) This is my chain of actions: ```elixir...

Unable to get authenticated with google, after following google login flows

Even if i'm successfully seeing the google login flow (on google side), i'm being redirected as unauthenticated with this toast error: "Incorect email or password", with no other errors in the console.

is there a way to perform a bulk update but for individual items?

given an input like [{store_id: 1, some_data: 2}, {store_id: 3, some_data: 9}], can I configure bulk_update to update store 1 with some_data 2, etc etc

reactor_req - argument option in dsl is missing

Weird because wait_for does work, which supposedly unsugars to argument :_, result(step_to_wait_for). Error:
Compiling 1 file (.ex)
error: undefined function argument/2 (there is no such import)

122 │ argument :agent_result, result(:generate)
Compiling 1 file (.ex)
error: undefined function argument/2 (there is no such import)

122 │ argument :agent_result, result(:generate)
...

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