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

AshPhoenix.Form fails in submit without errors with embedded resources

I have a embedded resource like this: ```elixir defmodule Marketplace.Markets.Property.OffMarket do @moduledoc false...

Issues using Ash.Type.Union

So I'm trying to use Ash.Type.Union and I keep getting errors when attempting to load the resource, I have defined an embedded resource ```elixir defmodule VMX.Transactions.TransactionData.Type.Call do...

Validate not nil, min and max for a string

The following validation code doesn't work: ```elixir attributes do uuid_primary_key :id...

What's the best way to learn Ash?

So i'm trying to learn ash, i don't want to just go through documentation. I want a better way to do it, but couldn't find courses that are up to date. I'm considering making a toy app, but not sure what's something that's beginner friendly and will help me gets the broadest exposure the Ash modules. I have considered making a to-do list, but in reality that'd expose me to maybe 10% of the framework....

Unexpected token during mix ash_phoenix.gen.live

I'm creating a toy application for tracking weight lifting workouts. I have a WeightType resource that I want to create a LiveView for. When running the Ash Phoenix LiveView generator I'm getting the following error and having trouble tracking down where it comes from so I can fix it. Help? `` mix ash_phoenix.gen.live Mitochex.Workouts Mitochex.Workouts.WeightType Would you like to name your actor? For example: current_user`. If you choose no, we will not add any actor logic. [Yn] n...

How To: Return a computed relationship in a read.

I have a resource like Posts. Each Post has a 'top comment'. So when i'm fetching a Post or list of Posts, I will like it to include the top comment like so: post.top_comment. I'm currently trying to use a preparation to load this relationship but not sure how to execute it on the Ash.Query side of things. Any ideas here would be appreciated!...

sort many_to_many

I thought I had asked this question before, but can't seem to find it... It seems like a very common use case, but not sure how to go about this. Is it possible to sort a many_to_many relationship based on a field in the join table....

Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.

I'm getting the above warning even though this module is indeed listed in the registry. What am I missing? ``` defmodule MyApp.Accounts.Registry do use Ash.Registry,...

Implementing token inactivity timeout with automatic expiry extend

Hi folks, I am using the ash_authentication password strategy with my resource configured to store all tokens, and require token presence. The project has a VueJS frontend that communicates with the backend via GQL. When a user logs in, the frontend receives the token and includes it in the header as a bearer token. This is all working well. I have set a short-lived token_lifetime, and would now like to add a way to log the user out after a period of inactivity, and also extend their session expiry whenever they make a request to keep them logged in beyond the initial expiry time. I have realised that this may be at odds with using JWTs as the token, as they are effectively tamper proof....

How to: DateTime validation with compare/2

Im trying to compare datetime in an action with compare/2. Code looks like this: ```elixir validate compare(:resumes_at, greater_than: DateTime.utc_now(:microsecond)), message: "resumes_at must be in the future", where: [present(:resumes_at)]...

Using code_interface args

When I use ``` code_interface do define_for Office.ToDoList define :create, args: [:subject]...

ManualRead not resolving in graphQL

Hi All, I have created a ManualRead module to implement a tricky relationship which has defaults that can be overridden. Before going too much into details, this ManualRead is working fine when I use the code interface, but when I call the same action through graphQL the values I expect are all nil. It is a bit too long to paste here, but was wondering if there is something general I need to think of when doing this?...

AshAuthentication missing notifications when running Expunger

I noticed that, for time to time, AshAuthentication Expunger is running and it will generate a warning because of a missing nofitication for removing tokens. Here is one of these warnings with the full stacktrace:...

How to effiently add thousands+ of entries to `many_to_many` relations

I'm having a brain freeze at the moment. I have Controls and Requirements with a many_to_many relation (ControlRequirement). I can set those using manage_relationship... however I now have the use case where I need to add new relations one by one ... thousands of them. My understanding is that manage_relationship with :append_and_remove expects a list ... so I'd need to fetch the list, add an item, remove duplicates and then provide this to manage_relationship, correct? I assume `:ap...

(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1

Gotting the above error while try this code for a regex search. Ash.Query.filter(fragment("task_id ~* '?\\d+'", ^prefix)) The Ecto doc suggests explicitly defining type withtype(^prefix, :string) but I'm not sure how it's supposed to fit in as an Ash.Query. expression....

InvalidFilterValue for read action

I have this relatively simple read action, but it keeps on failing with a %Ash.Error.Query.InvalidFilterValue ```elixir read :for_organisation do argument(:organisation_id, :integer) do...

Use without data layers

Hi, I'm trying to fit the example from https://hexdocs.pm/ash/use-without-data-layers.html to call a web api, `defmodule Asher.Edge.FetchMyip do...

How To: Atomic update with a where clause

I'm trying to implement this workflow: Update a timestamp atomically on an existing record if the new timestamp is greater than the old one, and the old one hasn't changed while im updating it(optimistic update). I know atomics just dropped on Ash core so wondering if this could be achieved with it. This is the ash action in question:...

Adding Postgres NULLS LAST to an Ash prepare build sort

Hi! I spent a little bit trying to figure this out and wanted to share to make it more searchable. Ash's sorts actually support NULLS FIRST and NULLS LAST as different options passed instead of the normal :asc, :desc, etc: ```elixir...

How To: Exclusion constraints in AshPostgres

Im setting up an exclusion constraint an a few time attributes. I dont see anywhere in the docs an affordance for exclusion constraints, only check constraints, so what I did is create the migration for the exclusion manually, but now im getting an ecto error asking me to add it to the changeset. ``elixir If you would like to stop this constraint violation from raising an exception and instead add it as an error to your changeset, please call exclusion_constraint/3` on your changeset with the constraint...