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

When trying to set password using my own update I get Postgres type error in AshAuthentication

This boils down to that Postgres can't find the correct type for a parameter. Is that something I can take care of or is it somewhere else? <former gist-link, replaced by many messages below>...

Ash.Resource.Calculation with field_policy

in a calculation Ash.Resource.Calculation I have the following load: ```elixir def load(_query, _opt, _context),...

Problem with load of User

I my user, I have the following relationship ``` elixir has_many :organizations, CauseBeacon.Organizations.Organization do no_attributes? true...

Problem with Ash.Type.dump_to_native/2 after upgrade to 3.5.41

After upgrading to 3.5.41 my tests fail when there is a "NOT IN" query, apparently where before dump_to_native cas called with the atom (:cancelled) now a string "cancelled" is used causing the postgres query to fail. This is my custom type: ``` defmodule Admin.Resources.Types.TimerStatus do...

How to load archived resources?

I need to have resource data available in other resource listings even if they're archived. Currently, they're being filtered out. How can I configure them properly for these use cases?
Solution:
if so you can configure a read actions that don't apply the filter using https://hexdocs.pm/ash_archival/dsl-asharchival-resource.html#archive-exclude_read_actions and configure the read action on the relationship e.g. with https://hexdocs.pm/ash/dsl-ash-resource.html#relationships-has_one-read_action

No actor in after_action context

I wondering what is the correct or recommended way of passing the actor down to a after_change callback. I've tried to use the context but the actor was always nil. I've ended up doing this: ```elixir actions do defaults [:read, :destroy]...

mix ash.codegen not detecting changes

I have just created a new project, added two resources to a new domain with mix ash.gen.resource, and mix ash.codegen is says No changes detected, so no migrations or snapshots have been created. I am also getting a strange compiler warning about redefined modules, which makes me suspect something has gone wrong with the generators.
mix ash.gen.domain ChocolateMusicPlayer.Collection; mix ash.gen.resource ChocolateMusicPlayer.Collection.Track --default-actions read,create --uuid-primary-key id --attribute length:integer:public --attribute number:integer:public --attribute position:integer:public --attribute title:string:public; mix ash.gen.resource ChocolateMusicPlayer.Collection.Release --default-actions read,create --uuid-primary-key id --attribute date:date:public --attribute title:string:public --relationship has_many:tracks:ChocolateMusicPlayer.Collection.Track
mix ash.gen.domain ChocolateMusicPlayer.Collection; mix ash.gen.resource ChocolateMusicPlayer.Collection.Track --default-actions read,create --uuid-primary-key id --attribute length:integer:public --attribute number:integer:public --attribute position:integer:public --attribute title:string:public; mix ash.gen.resource ChocolateMusicPlayer.Collection.Release --default-actions read,create --uuid-primary-key id --attribute date:date:public --attribute title:string:public --relationship has_many:tracks:ChocolateMusicPlayer.Collection.Track
Diffs look fine. I accept each Proceed with changes? prompt....
Solution:
do you have AshPostgres.DataLayer in your resources? you probably need to add --extend postgres

`on_conflict: :nothing` for a create action

Is there a way to set something like on_conflict: :nothing for a create action? I've added this to my action, but IMO it looks weird: ```elixir...

destroy unmatching related associations

I'm currently trying to destroy the associations in case the attribute is an empty list with this change ``` change manage_relationship(:owner_teams, :owner_teams, type: :direct_control,...

AshPhoenix checkboxes acting wonky

My form (slightly abbreviated): ``` <.form for={@form} id="storefront-form"...
Solution:
Had claude check my input components against a fresh phx.new core components and now it all works. Thank you for that (in hindsight) obvious place to look. I have been debugging like crazy lol.

Membership FilterCheck

Hello lovely people 👋 I’ve been working on a custom SpaceMemberFilter policy check (using Ash.Policy.FilterCheck) with a goal to authorize access if the actor is a member of the space associated with a given resource (optionally filtered by actor’s role in given space). I took inspiration from Ash.Policy.Check.RelatesToActorVia, but instead of comparing to a single actor ID, I need to check whether the resource’s space_id is in the list of the actor’s valid space memberships....

Custom on option on update action

What is the idiomatic way to pass a custom option to an action. Id like to achieve the following:
update_contact_cool_action(contact, attrs, push_sync: false)
update_contact_cool_action(contact, attrs, push_sync: false)
...

Table renamed but old table remains

Hi all. I renamed a table from automobiles to cars like this: ``` postgres do table "cars" # Used to be automobiles...
Solution:
mix ecto.gen.migration gets you a one-off migration

Invalid Filter Reference

I'm getting an Ash.Error.Query.InvalidFilterReference I'm trying to push a particular filter into the DB level. I have this calculation, which works: ```elixir...

How do I make a query require authentication and return an error if the user is not logged in?

Currently, the query returns nothing when there is no user logged in. But I would like it to return an authentication error.

AshAi tools

how do I get the schema of a tool?

Grab my user's tenant name so I can display it

I am currently doing something like this in order to grab my user's tenant. Is this the correct approach? ``` pipeline :browser do plug :accepts, ["html"]...
Solution:
sign in does not share state with your liveview, but you can put the tenant name in the session

AshAi tool calling

I have a weird case where most of the fields are arrays, and when the ai triggers a tool call it checks equality instead of inclusive-ity, is there a way to combat this. it's using the underlying filter option so I think it know that the attribute is an array but it's using equality [:eq] instead...

Tenant registration on sign-in.

Can someone point me in the right direction to implement the below flow for GitHub-only auth? Case 1: User exists and belongs to an org -> User is signed in via GitHub ...
Solution:
If not, then you can just put something in the router for if the user is signed in but has no organization_id they get sent to a different page

Prevent accessing route if logged in

Is it possible to prevent a user from accessing a page if already logged in? I remember vanilla Phoenix having something like :redirect_if_user_authenticated but I can't find the Ash way to achieve this....
Solution:
You could do it at the router level, but you could also add a policy on the action