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

Slow pages ... due to too many load of data...

Hi Community, In a platform I am currently developing, some pages are slow. Too many load of data... I am wondering if there is a config option that permit to have in the log the files/component/lines that call the ash.load or Ash.get... which do the SQL access to the DB ? In order to analyze the issue quicker ?...

Getting protocol Phoenix.HTML.Safe not implemented with "Ash Phoenix"

Protocol.UndefinedError at GET /profile protocol Phoenix.HTML.Safe not implemented for type AshPhoenix.Form (a struct) Got value: ...

Working with Transactions

Hello! I'm working on converting the following Elixir/Ecto function into an Ash action: ```elixir def create_team(attrs, user_id) do...
Solution:
```elixir change fn changeset, context -> Ash.Changeset.after_action(changeset, fn changeset, team -> team_member_attrs = %{ # actor is in the context...

How to ergonomically add/remove to an array of embedded resource in graphql

The docs state flatly that if you do updates on an array'd embedded resource it simply calls destroy on them all, and then recreates them. This makes sens as you typically atomically replace the json blurb on read/write. I have to model this as embedded as I am sharing the table with a legacy system in a transition period, or I would just model it as actual rows and use manage_relationship. Right now I am looking for the most ergonomic way to have addFoo and removeFoo mutations in my parent resource....

Using manage_relationship with bulk_create

I'm having trouble using manage_relationship with a bulk create. I want to be able to create a bunch of "child" resources in one request while also providing attributes to create their "parent" resources at the same time. In a normal create request, I can create a child and parent at the same time, but in a bulk create, it seems like it's trying to insert the parent resource twice. Child resource: ``` actions do...

Ash.Type.Tuple Enumerable not implemented

I have an attribute of type :tuple defined like this: ```elixir attribute :model, :tuple do constraints [...

Correct Way to Display Spark.Error.DslError?

Hi! I’m writing a custom DSL extension and I’m struggling with making Spark.Error.DslError show up in the right place. I followed patterns from core Ash code (like default_accept.ex and verify_identities.ex), and also looked at extensions like Ash Cloak. Here's what I did in my verifier: ```elixir...

Auth flow

I have an auth flow that I am wondering how I can best model in Ash. I have tens of thousands of members that I have the info of, most of which will not log into the app. Maybe up to 10 000 real users, some which will be very infrequent. So I would like to use the magic links only not have them manage a password. I also want people I don’t know the email address of to be able to log in, and fill some info to be reviewed by a human. Some even turn into volunteers but don’t want to become members. So they should be tracked in a different table....

Complex Custom Actions

How do you usually model complex operations over a model? I have a model that needs to do some processing over their inputs, it handles everything related to subtitles, and after creation it goes over several stages of analysis of the context and such and I'm struggling to fit it inside of the Ash framework. I was thinking to model it in two ways:...
Solution:
before_action hook or before_transaction hook depending on how costly the analyze_content() function is

Calculating average number of sessions per user

I have the following resource: ``` defmodule MyApp.Ash.Dashboards.SessionEvent do @moduledoc """ Resource that maps to Analytics DB session_events materialized view...

receiving an Ash Error and don't understand why

question about this error. I'm trying to setup something similar in my app that the Tunez book does. Following an artist, but I'm wanting to like a post. Here's the code ```elixir post.ex (resource) has_many :like_relationships, App.Elevate.PostLike...

Igniter stuck in loop on brand new install

I have a brand new install, when I run the command (provided by https://ash-hq.org/#installer), it gets stuck in an infinite loop of: ```setting up igniter ✔ compiling igniter ✔ setting up igniter ✔...

many_to_many in ash

```elixir defmodule Consola.Database.ShortUrl do use Ash.Resource, domain: Consola.Database, data_layer: AshPostgres.DataLayer ...

Question about somewhat unusual join relationship

Imagine we have User, Opinion and Event. Opinion is a join resource between User and Event. The tricky part that I want to support is for Opinion to have nullable user_id, where an opinion without a user is a default opinion. And when we query opinions/events for a user we want to include default opinions for events which the user has not specified/created their own opinion. Sounds like something for sort based on user_id and distinct based on event_id. And this combo does work if we query things for a single user but if we load things for multiple users there appears a problem - read action is used to read all users opinions together. Because of that it results in removal of a default opinion if any one of requested users has its own opinion (distinct gets applied to whole query not per user). Which means that if one user has its own opinion about an event then other users, who do not have their own opinion, lose their join link (default one). I'm interested if it is possible to make this work without using manual relationship....
Solution:
I think many to many relationships essentially only support join resources that are distinct on the two columns in question currently, we should probably be showing an error about it TBH

Book seed issue: Tunez.Music.Artist.read had no matching bulk strategy that could be used

When I try to run the first seed script for artists from the book code I get the following error message: ``` ** (Ash.Error.Invalid) Invalid Error ...

Framework Error - Assumption failed: Invalid return from calculation

Hi, I’m encountering a Framework Error with the message:
Assumption failed: Invalid return from calculation, expected a value, got %Ash.NotLoaded{}...

I want to load related records inside "relationships" key

Hi! I'm following the Ash book, specifically on loading related records: ```elixir json_api do type "artist" includes [:albums]...

How to use Ash.Notifier.PubSub filter?

The docs say the filter takes a function with the Notification as the argument and must return a truthy or falsy value. Does it work like this? ```elixir publish :action, "topic" do filter fn notification -> notification.data.status == :done end...
Solution:
Yes that looks right to me

Error message in a grapqhl mutation

``` == Compilation error in file lib/safari_web/graphql_schema.ex == ** (KeyError) key :error_location not found in: %AshGraphql.Resource.Mutation{ name: :supplemental_document_create, action: %Ash.Resource.Actions.Action{...
Solution:
looking at the commit that adds in the bit causing the error https://github.com/ash-project/ash_graphql/commit/4bcea7846fbcd752bce94047135ed83780f26204 and it suggests that you should have AshGraphql.Resource.Action structs but you have Mutation structs instead - so it might be defined in your schema incorrectly

Return only selected fields

How do i return only the selected fields instead of the whole struct? Cant seem to find a good example for the action based version ```elixir read :select_specific_fields do prepare build( select: [:id, :name]...