Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

Create action with multiple nested resources

This is the action to register an account. There are 3 resources at play. An account has many memberships and every membership belongs to a user. The membership resource is simply as has_and_belongs_to_many with a role on it. When a new account is created, it should always create the account and membership for the owner/user. The user resource has an identity on email and is only created if the user doesn't already exist. What happens is the membership fails to insert because the user_id is nil....

Implementating auto-incrementing/sequence fields in Ash Resources

I'm working on a project and I need to implement auto-incrementing fields, for example an Issue Number, Invoice Number, Service Number etc. I was thinking of creating a sequence table to keep track of multiple auto-increment field counts. issue_number counts, invoice_number counts, service_number counts, etc. I want to make sure that the implementation is consistent and that the sequence table will not leave gaps, as some database implementations leave gaps when a transaction fails....

All extensions list.

In one of the talks i heard cqrs/commanded mentioned. Is there some package at least in beta or smth? And broader question is where are list of all extensions, even 3rd party? I understand that ash currently is pretty young and theres probably not much, but i see huge potential in reusability and having something like https://tailwindcomponents.com/ but for ash resources.

Publish :create, ["created", deeply_nested_item_id]

Let's say my resources have this relationship, chat_room has many posts which then has many comments. and I want to have this pub_sub definedin comment.ex. ```...

Nested embedded Resource Form

I have an embedded resource which contains multiple other embedded resources. When I use AshPhoenix.Form.for_update with forms: [auto?: true], the form created does not contain information about any of the embedded resources other than the first key. Right now I am adding the missing data like so ``` update_form = AshPhoenix.Form.for_update(styles, :update,...

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