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

How not to select fields when loading a resource

Is there a way in Ash to not select a field when loading a resource? We have some fields in the DB that are really large and we don't need to select them most of the time. Is there a way to tell Ash not to select that field for this particular load or action?...

How to put the same value at multiple places in a fragment?

Say I have a custom postgres function and Is it possible to do the following fragment fragment("SELECT my_custom_function(1/<rate>, 2/<rate>, 3*<rate>) FROM lookup_values WHERE id=<id>", rate, id)? Today, I will need to do fragment("SELECT my_custom_function(1/?, 2/?, 3*?) FROM lookup_values WHERE id=?", rate, rate, rate, id)...

How do you sort by substring?

Current in my resource ```actions do defaults [:read] read :list do...

Actor not passed to `read` action after `create` action

I have a resource with a default :create action and :read action, and an AshGraphql mutation that calls :create. The resource has a module-based policy that requires the actor have a certain "role". When I test the mutation, the policy allows the actor to perform the :create, but when it checks the :read action that happens at the end of the mutation, the actor passed to the policy is nil. What makes this especially confusing is that I have other resources that are set up the same way, and they don't have this nil actor problem. I'll post my code in the comments below....

Manual relationship with recursive CTE

I'm trying to implement this comment/thread (https://discord.com/channels/711271361523351632/1110614023881359430/1111297127897890866) and creating a manual relationship with a recursive CTE (for a tag in a graph structure, get all parent tags). I'm able to get it done with Ecto spitting out grouped map lists. I'm getting a bit stuck figuring out how to get them as an Ash Resource in the end. Is there anything major I'm missing? ```elixir...

action argument default to another argument?

Trying to use the value passed in one argument as a default value for a second argument. Is there a way? Something like: ```elixir create :new_record do primary? true argument :short_name, :string, allow_nil?: false...

Possible to use relationships for Identity?

```elixir defmodule One.Exam.QuestionParagraph do use Ash.Resource, data_layer: AshPostgres.DataLayer ...

How should module calculations return errors?

Since the name of the function calculate/3 doesn’t end with ! and returns a raw value instead of an ok/error tuple, I’m just checking whether it’s OK for my custom calculation (defined in its own module) to raise an error which can be caused by, say, an attribute having a value of an unexpected type or an invalid string format (this would be caused by a bug in the app — I’m not trying to code a validation in a calculation).

Broadcasting pubsub update notifications only if the resource has been changed?

At the moment a broadcast is made after the action is successfully performed - even if nothing on the record actually changed. My scenario is having a background worker that checks validity of some credentials in a loop periodically, in an action like so: ```elixir...

Ash.Query.load not loading nested relationship?

```User |> Ash.Query.load([friendships: [:first, :second]]) |> Accounts.read!() #Ash.Query< resource: User,...

How best to model partial updates of optional attributes?

The classic example is a "user settings" page, where if they only change their username but leave the password field blank, you want to not update the password, but instead ignore it. The best I can come up with is something like this: ```elixir...

Polymorphic Self References

Can't seem to figure out how to accomplish the following. I have a polymorphic table that is meant to model a tree relationship. this of course requires a belongs_to and has_many relationship to itself. How do I go about defining a self referential relationship that is mean to pickup on context provided by the consumer? Such that all the relationships are within the same table? ```...

How to create a second resource on a create action?

what is the best way yo create a second resource durning the creation of a first one? for example in a Workspace resource that should have a Wallet resource as has_one relationship...

How to set belongs_to on in a form

I have a create action for Plan that sets the Product (Plan belongs_to Product) ```elixir create :create do primary? true...

Policy authorizer not applying to read action

I have this policy ``` policies do policy always() do authorize_if action(:create)...

How to pass args to Api.read

I'm trying to accomplish something like this
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
for an action that looks like this ```read :list do...

Many_to_many on email destination

I'm try to create a many to may relationship between a workspace and a user, using user email instead of the user id. But when i try to create the a WorkspaceUser I get an error: ```elixir ** (Ash.Error.Invalid) Input Invalid * Invalid value provided for user: cannot provide structs that don't match the destination....

Invalid association, not an ecto schema

I'm getting a strange compile error that I can't replicate locally, only in GitHub Actions, I'm on the latest version of everything, ash deps, elixir and erlang. `` ==> spendable Compiling 5 files (.ex) warning: invalid association budget` in schema Spendable.BudgetAllocation: associated module Spendable.Budget is not an Ecto schema...

Can't add form with auto forms

I'm getting this error when setting up with auto forms. Attempted to add a form at path: [:budget_allocations], but no create_action was configured. here is my action ```...

Expected at most one result but got ...

I'm not sure if I've encountered a bug or not. I have the following action: ```elixir read :get do...