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

Error Loading 3 `no_attributes?: true` nested relationships

I'm running into an error that's very similar to one I encountered before. The structure is Grandpappy > has_many > Parent > has_many > Child > has_many Toy Grandparent also has_many :grandchild_toys via a no_attributes?: true relationship:...

Single File Ash Authentication

https://gist.github.com/TwistingTwists/7e17076db32e22b4e46e8fa15e3ae64c This is an attempt to have a single file AshAuthentication working with password strategy. however, on the localhost:4000/register route i cannot see any form. Should I build one?...

AshGraphQL bulk operation

How do I make graphql perform bulk upsert? I couldn't find anything in ash graphql docs, but I saw ash supported bulk actions...

ash.codegen --dev & ash_ai / vector attr type

Not sure if this is an ash_ai thing or an ash.codegen --dev with vectors thing, (I'm guessing the latter) but my project is deadlocked now since it wants to add this: ```use Ecto.Migration def up do...
Solution:
fix released

AshGraphQL mutation with metadata

I want to make a File resource, which will have a path to S3, a filename etc. And I want to define a :create action :sign_upload_url that will return a metadata :upload_url, however I can't make it return the metadata from mutation
Solution:
```elixir create :create do metadata :foo, :string ......

Testing liveviews requiring users to be logged in.

I'm only using the magic link strategy and I'm following the test setup from tunez to configure my tests. However, I'm getting this error - ** (KeyError) key :token not found in: %{selected: [:id, :role, :email, :updated_at, :inserted_at, :organization_id]} when I try to create a user and sign it in for the test. this is the test: ...
Solution:
Solved the issue. registration is disabled, so I had do create a user with a regular create action. then to sign in I had to perform the following incantation: ``` strategy = AshAuthentication.Info.strategy!(MyApp.Accounts.User, :magic_link) {:ok, token} = AshAuthentication.Strategy.MagicLink.request_token_for(strategy, user)...

Zipper replace and Rewrite

I'm playing around with igniter trying to figure this out. Not sure if on the right track. :thinkies: Let's say I got to a change block and I Sourceror.Zipper.replace replaced the third argument with a module that I will also create. I was thinking of doing like a git diff, which I think diff_and_yes? function does. But I can't figure out how does this relate to rewrite/source. ...
Solution:
You can use Igniter.do_or_dry_run

before_action in bulk_create

I'm implementing some logic that would bulk_destroy existing records and bulk_create in a transaction ``` create :replace_signatures do...

Invalid default values

One resource runs into an issue that I haven't had before and cannot solve. I've already updated all dependencies and removed the _build directory without success. The resource has some attributes ```elixir attribute :prefix, :string...
No description

Shared Validations

Where are shared validations typically stored? For example, say I have a User resource that has an email that has format and length requirements. Say there was a second resource where I wanted to share those same validations. Where would I store that? Normally I would put it in the MyApp.Accounts.User.Validations.Email module, but I'm not sure if that's appropriate to share across resources as a validation. The only alternative I can think of is having something like `MyApp.Accounts.Shared...
Solution:
There's no hard rule, but for me it's typically just MyApp.Domain.Validations...

Best way to run bulk ops in a transaction

I’m new to Ash, and I have a fairly simple code problem. I need to delete all the records for a resource for a given user and then bulk create new ones of the same resource for the same user. I want these two bulk operations to be in a transaction so they’re rolled back on error. I’ve been able to do this in a generic action by using bulk_destroy followed by bulk_create. However, I’ve not been able to figure out how to do this in a multi-step way by using callbacks (to delete first) which seems like it would be the Ash way. Am I missing something or is a generic action the way to go?...

Does `mix ash.codegen` generate drop migrations for deleted resources

I'm removing a couple resources and after deleting them mix ash.codegen says everything is up-to-date
Solution:
it does not, you'll have to do your own migrations for that currently

The domain Foo.Bar requires that an actor is provided at all times and none was provided.

Noticed this when running tests against latest main. We have our domains set up like: ```elixir authorization do...
Solution:
just pushed to main

Having some trouble with a bulk update

I have something like: ```elixir update :backfill_code do change fn changeset, context ->...
Solution:
I just pushed a fix to setting batch_size to main

Add value to manage_relationship input from current resource

I have this resource ```ex defmodule Aldente.Management.Invitation do use Ash.Resource, domain: Aldente.Management,...

AshGraphQL bulk upsert

I wanted to expose a bulk action on graphql, and there are no available options in create macro, My main concern is argument type generation, if not for that, I could write a custom handler, Is there a better way to handle this?
Solution:
Currently there is no builtin way

manage_relationship: Get changes in related records

My Invoice resource has many Items. Every item calculates its total in a change. I want to calculate the sum of those totals in the invoice but cannot find a way to read the full items, only the input. How can I do this? ```elixir argument :items, {:array, :map}, allow_nil?: false change manage_relationship(:items, type: :create)...

Reactor persistence and user tasks

I have a fairly involved saga I want to implement that I have currently as adhoc liveviews but that I want to make a bit more robust. Reactor seems fairly good for this (although I don't really need rollbacks). This saga includes both automated tasks (call some APIs, generate some data) and user-led steps, where the user has to interact with some stuff. Is this something that reactor would be good for? Would you create a model that stores the current step in the DB and then restarts from the nex...

Having trouble getting started with Ash

Hello, On Reddit yesterday I mentioned getting stuck with the startup with the Ash framework, I have gotten different issues different times but this was my most recent one I used the Ash websites code recommendation to get started, all I did was run the curl command which downloaded everything then I entered the directory it created and just running the igniter install commands fail...
No description

How to model context based multitenancy?

What would be the best approach to load the tenant info into the user when working with context base multitenancy? - If I use global? true I can log in without knowing the tenant, but I'm not sure what the best strategy to fetch the tenant into after - or during - sign in, given the current_user has no tenant data - If I use global? false I need the tenant info before sign in, which can be work. I just need to figure it out how to build the magic link with the tenant subdomain - probably a phoenix question though. Should I define my user resource as?...
Solution:
Yes you should likely do that 🙂