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

Identity on two attributes causing errors

I have an identity on two attributes (context, and token). I would expect this to require a unique context <> token. But it's not allowing duplicate contexts. Here's my resource: ```elixir...

Sorting with calculation result giver "Argument value is required" error

I have the following query: ```elixir Markets.Property.Offeror |> Ash.Query.filter(...

`AshGraphql.Error` not implemented

Looks like a policy error is being raised and not caught somewhere: `` [warning] fb1756e7-6a42-43c1-a11c-9758d305ac78`: AshGraphql.Error not implemented for error: ** (ErlangError) Erlang error: {%Ash.Error.Forbidden{errors: [%Ash.Error.Forbidden.Policy{scenarios: [], facts: %{false => false, true => true......

Ash.Query fragment inside a select?

Hello, I'm trying to replicate this query with Ash.Query: ```sql WITH constants (value) AS ( values ('hue') ) SELECT...

Patterns for Propagating Tenants to LiveComponents/LiveViews?

This is a Noob / organizational question. But I just added attribute multi-tenancy to my app. I have the correct tenant loaded on login, placed in the conns, and in the session via ash_authentication.phoenix.livesession. I am grabbing the tenant from session in a LiveView to be added to reads . For handle_events, and all LiveComponents which talk to the DB, I assume I'll need to pass the tenant in via assigns? Feels like it could get a bit messy, especially for LiveComponents. Does any...

How to make simple select count with Ash

Hi, maybe a noob question here 😅 but I'm wondering which is the right way of making a simple select count of my Users on a Postgres-based app. I could do that with MyApi.count(MyResource) but on the docs that method belongs to the ambigous Ash.Filter.ShadowApi module. ...

GraphQL Subscriptions

Are they on the roadmap? Is there an existing pattern for getting them going using Notifiers?

Handling an %Ash.Error.Invalid{} in LiveView

Sorry for the noob question, but the AshPhoenix guide doesn't show any error handling. This is the code that I assumed would work, but update returns a {:error, %Ash.Error.Invalid{} } How do I get those errors onto the form? ```...

AshAuthenticationPhoenix Override Register Form

I want to add a form field on the register form, specifically tenant information for attribute based multitenancy. I see that there is a register_extra slot which receives the form, so I was thinking I could use that. Is there a way to override just the Password.RegisterForm to a custom component (assuming that is how I'd add the slot)?...

Ash Query filter function

For background information I have binary field in my datalayer called token when I call this the following function: ```elixir %{id: id} = user = insert(:user) assert {:ok, %My_App.Ash.User{id: ^id} = _user} =...

Does attribute `default: _` not set the struct's default value?

It appears that when defining an attribute's default: value, it doesn't set the default on the generated struct definition. I would expect it would, like Ecto.Schema does. Is there a reason it doesn't? Or is there a way of accomplishing this that I couldn't find in the documentation? ```elixir defmodule GF.Ash.WebComponent do use Ash.Resource,...

Issue using datetime_add

Hello, thanks again for the awesome library, I was trying to get into some more useful functionalities of Ash (calculations, etc.) and I'm mostly having a good time learning about it but there was one bit that I was having a hard time with. I was modeling an appointment, which I wanted to store the start date and the duration of. I thought calculating the end time would be useful, so I added made the following resource: ```elixir use Ash.Resource, data_layer: AshPostgres.DataLayer ...

Using Ash Resources as input types

I've occasionally encountered issues using Ash resources as input types to actions of other resources. The most common patterns I've seen to resolve this are to simply turn the inputs into a map and let manage_relationship figure it out, or to take as a parameter only the :uuid and similarly construct a map with just %{id: uuid} for manage_relationship. The culprit in some cases seems to be AshGraphql, which errors following this pattern: ``` == Compilation error in file lib/app/schema.ex ==...

Use Ash policies with simple functions

I was wondering if there is a way easy way to use Ash policies in places that you don't actually have an Ash resource. For example, I'm using FunWithFlags package for feature flags. I have a live view to handle the flags, and also a context module for it. Now I wan't to create some authorization code to this context module, and since I'm already using Ash for the rest of the system, I was wondering if there is a way to configure policies for a specific function....

Re-sort items in a form without submitting the form

Let's say I have a form to input a lit of to-do items, and want to give the user up/down buttons to reorder them based on priority. I can probably change the priority value via phx-click event, but I'm not sure what's the best way to display the items reordered based on the new priority values, without submitting the form. I'm guessing it should be done in the 'validate' handle_event, which currently only includes this.
form = AshPhoenix.Form.validate(socket.assigns.form, form_params)
form = AshPhoenix.Form.validate(socket.assigns.form, form_params)
...

cross_join on a Ash.Query

Hi I am able to do a cross_join on a Ecto.Query style. I am not able to convert to the Ecto.Query -> Ash.Query o r I am not able to perfrom Ecto.Query.from style cross_join on the Ash.Query in the prepare fn....

Destroying related resources

I have some related resources with existing actions utilizing manage_relationship to create and update them. For destroying, is it pretty much the same process, where the form has all the nested subforms and then I take those in through arguments and manage_relationship them and destroy them? I haven't seen anything explicitly on this topic in the documentation or here, pardon me if I've missed it. I want to make sure I don't leave any orphaned resources, which the loaded form on my edit pag...

Not seeing policy authorization errors

I'm adding policies to my app, feeling my way to the correct modeling of my domain, and when submitting an action all I see in iex is: `` [warning] Unhandled error in form submission for Panacea.Accounts.User.add_user This error was unhandled because it did not implement the AshPhoenix.FormData.Error` protocol....

Policy engine duplicates/optimizations

To what degree does the policy engine internally prevent reexecution of identical policy checks? Will it evaluate a given MFA only once per request? If so, is there a way to indicate that a policy check is e.g. not dependant on the underlying record?...

Guides or advice for migrating to Ash?

I have a small app with 3 tables in Postgres using Ecto.Table. I am migrating them to use Ash.Resource. When I run mix ash_postgres.generate_migrations for the first time, the generated migrations are to create tables that already exist and the table structures are different. Are there any guides or do you have any advice for reconciling the differences? Original ecto migration:...