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

Set error message on attribute using AshAuthentication.Strategy.Password.PasswordValidation

When a password validation fails on a liveview form submitted. How do I get an error on the :current_password attribute? ```elixir AshPhoenix.Form.submit(socket.assigns.password_form, params: params, actor: socket.assigns.current_user) ...

undefined root_level_errors? true

Hello, small problem here. I am doing something like this ```elixir change fn changeset, _struct -> changeset |> Ash.Changeset.change_attribute(...

If I set an argument default in a Flow I have it `nil` in a custom step

```elixir defmodule MmsBiztalk.Flows.Rollback do use Ash.Flow flow do...

Testing with log_in_user

I'm writing tests and have a helper to log_in_user that I found in ash-hq source. ```elixir def log_in_user(conn, user) do conn...

Limiting action sort and filter

I'm going through and starting to audit my setup for sorting and filtering. Ideally, it would only be possible to sort and filter on a limited set of attributes/relationships. I can block anything I don't want with filtering_on policies, but I'd like to get it out of my GraphQL schema and JSON:API altogether. Is there a way to define at the action and/or resource level which attributes and relationships are allowed to be sorted and filtered on? If there is a way to do this, is there also a flag that would set these to [] by default globally? I'd prefer to explicitly allow rather than deny. This seems to be in-line with the planned changes for Ash 3.0, re: accept defaulting to []....

function to_form/1 is undefined

I literally followed the "Getting Started With Ash And Phoenix" documentation example. Upon finishing and typing "iex - S mix phx.server" and pressing enter, I got the following error: == Compilation error in file lib/my_ash_phoenix_app_web/example_live_view.ex == ** (CompileError) lib/my_ash_phoenix_app_web/example_live_view.ex:41: undefined function to_form/1 (expected MyAshPhoenixAppWeb.ExampleLiveView to define such a function or for it to be imported, but none are available) ...

Shorthand for code interface filters

Is there a handy shortcut for doing something like: ```elixir use Ash.Expr Post.read! expr(title == "Nice")...

Resolve notifications warning in when running tests

I'm getting this warning when running my test suite. It's coming from (I think) AshAuthentication sending confirmation emails. I'm not sure how to resolve it. ```elixir...

Nested form with filtered subform elements

Let's say there is a nested form with Tweet as the main and Comment as the sub. The requirement is to only show and make editable the comments entered by the current user in the subform. I'm hoping to accomplish this without using CSS tricks of hiding other users' comments. By loading filtered records into the form using the code below, I was able to make the form look like what I want, but when I submit the form, comments previously made by other users (apparently, filtered out from the form) seem to be removed. Is this the expected behavior of a nested form? Is there a relatively easy way to make it save the change without removing other users' comments?
``` def tweet_load(current_user) do...

Parse a new FilterForm from url params

I don't know if I'm missing something, but I can't find a way to fetch the components from a filter form as a map to add it as params for the URL query and then parse it back to a new FilterForm from these same params? For example, let's say I have a FilterForm with 2 predicates, I want to extract that information into a map so I can use it to form my url like this: ```elixir...

What is the "Ash way" to auto update related resources ?

Let's say that I have an invoice (postgres) resource and that it has_many lines. Let's say that I want the total_amount field of my invoice resource to be updated with the sum(amount) of all lines every time that a line is created, updated or deleted. What would be the idiomatic way to do that ? I understand that I should probably use aggregates and changes with an after_action, but I have a bit of a hard time to see exactly how to articulates all the pieces together.

Not getting pub_sub notification

Trying pub_sub the first time using Ash, so I could be missing something very simple. The console shows a debug message like this, but the liveview handle_info isn't triggered. Do I need any other plumbing code than what's shown in the code excerpts below? ``` [debug] Broadcasting to topics ["items:update:bcb9b300-22b9-474e-8a8a-81473568e438"] via MyAppWeb.Endpoint.broadcast...

Singleton resources

Singleton being defined as: "There is only ever one, no more and no less." Is there a recommended pattern? So far I have something that is basically anAsh.Resource with create, read and update actions and: - Does not allow anybody to call create, and does not expose it via frontend channels; - Automatically populates the record if it does not exist with the bare create using authorize?: false;...

How to create has_one relationships in a nested form

I have a resource called Transaction that has a has_one relationship with a resource called RecurrencePattern. When creating a new transaction (usually through a form in LV) I want to also create a matching recurrence_pattern. This works great when using the create action directly, but I'm getting an error when using an AshPhoenix.Form (I believe I got it to work at some point but don't know how to get back there again 😅 ) This works: ```elixir Transaction.create!(%{...

How to do polymorphic relationships, but with only 1 table?

Apologies if this has been answered before, but I couldn't find it in the search function. I want to create a table called transactions with the following columns: ```...

Nested form error - using create when I (think I) want update?

I have a nested form that has been working wonderfully to edit a Site and its related resources, and now I'm attempting to manage the Users who will be permissioned to use the Site as well. When I click to do my add_form for Users, I get a crash with: ``` [error] GenServer #PID<0.25850.0> terminating...

Load relationships on inserted ressource

I was wondering if there was a way to load relationships by default on an inserted ressource after a successful submit of a for_create form? The goal here is to simply append that newly inserted ressource to a list afterwards, but I need some relationships to be loaded on that ressource. I know I can do it manually, but I was wondering if there was a way to define some defaults "load" somewhere? Thanks a lot in advance 🙂...

AshStateMachine transitions from/to multiple states and no default initial state

Is there a way I can pass an array to from: and to:? Right now for the latter case it only makes sense if I can explicitly pass the state to transition to in the change builtin. Can I not specify a default initial state, and simply require that it be one of a set of initial states and not be nil? Tagging this Core for now....

ash_admin update to Surface 0.10.0

Is the update of ash_admin to surface 0.10.0 mentioned @ https://github.com/ash-project/ash_admin (2 days ago) available in hex.pm? If not, what would be the best way to update to fix for Surface 0.10.0. Getting the form macro expansion problem at compile time. Thanks for your help.

How to compare a seed and loaded resource?

I thought strip_metadata() would make the comparable ```elixir user = Ash.Seed.seed!(%User{...}) loaded_user = User.get_by_id!(user.id) |> Ash.Test.strip_metadata()...