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

`on_match: :error` should error on unique key violation?

Hi, I want to make an invitation accept action, invitation has a relationship member which is a belongs_to from Member, it has user_id, entity_id, which is a unique pair, I want to make accept create a :member relationship, so if a user accepts an invitation that is already in entity, it will throw unique identity violation This is what I have ```ex...

Thoughts on updating `ash_geo` to follow current ash extension patterns?

I'm considering using ash_geo, but noticed it doesn't use the same patterns extensions like ash_money for installing postgres extensions and types. I know it's not owned by the ash-project org, but wanted to see what people thing about giving it an overhaul to have a nicer installation experience and follow current extension patterns.

How do cleanly do action accepts for resources with a lot of attributes without `:*`?

With :* being deprecated in the future major version of Ash. Will you have to put all attributes in the accepts for the actions need to support all attributes? The answer very well may be you just have to list all the attributes in the action. But wanted to check....
Solution:
default_accept in the top level actions block

Is there a way to not sign in users automatically after they register ?

I'm having that behavior by default
Solution:
The first one I'd suggest is to just have a plug after the user is set from the session that redirects all unconfirmed users to a page that says "please confirm your account"

Change in how `Ash.Changeset.force_change_attributes` handles `nil` values?

i'm currently in the process of upgrading to the latest version. there seems to have been a change in how Ash.Changeset.force_change_attributes handles nil values? at least, that what i seem to be observing. here's a simple example:...
No description

How do I use a Union type as an action argument?

Given the following module and union type: ```elixir defmodule Insi.Subscriptions.SubscriptionPlan do use Ash.Resource......
Solution:
You can't use the tag/tag value for types that aren't maps

Adding a custom sort

I have a field which is an atom. I want to sort it with a custom sort order: I am imagining something like this but I can;t find the exact syntax: prepare fn query, _ -> query...

Return a single record from a manual read

I'm using a manual read action to wrap an api client around a resource I want to fetch an indivdual record but the get? true only applies to the data layre, how can I instruct the action to return a single record?

Create a ressource with multiple relationships

The docs specifiy how to create a post -> comments relationship (so in the same direction as the has_many relationship But I couldn't find how to create a ressource that has multiple belongs_to With the post -> comments example,...
Solution:
And write the ids. Or you can use the argument + manage_relationship pattern which you can see in the relationships guide

ExUnit async: true {:error, :table_not_found} with Ash.DataLayer.Ets

I've recently done a refactor on a test suite to allow all cases to run asynchronously. Unfortunately at some point I've started getting intermittent :table_not_found errors thrown on the actions of an Ets backed resource. It's almost guaranteed to happen when the whole suite (200+ tests) runs asynchronously. Is this expected? Meaning Ash.DataLayer.Ets isn't ready/meant to be used with asynchronous tests or am I missing some proper setup? For reference, these Ets backed resources serve as an in-memory cache to avoid hitting the DB constantly. The main use-case is to cache actor/account permissions to be used by policies....

Trouble with relationships and form

I have the following: ``` update :post_task do argument :task, :map do...

With AshPostgres, what is the proper way to create a exclusion constraint in a ash resource?

For check constraint, we can do it like this ``` postgres do table "rate_plans" repo MyApp.Repo...

Trouble Understanding Reactor

I'm taking a stab at implementing a Reactor, but the documentation isn't very clear. I've read both the Reactor documentation and the AshReactor documentation for getting started, but I'm still getting tripped up. Here is a basic example: ```elixir defmodule MyApp.Accounts.Reactors.RegisterUser do @moduledoc false...

How to restore LiveView state when using infinite scroll when browser back button is clicked?

I have a UX problem I'm trying to solve and not entirely sure how to go about solving it. User is on LiveView 1 that is a list view using infinite pagination + sort params + filter params User clicks on a record that navigates them to the record details LiveView 2 When the user clicks the browser back button, they expect to be taken back to the list view in the same state with the scroll position restored showing the record they clicked on....

Getting Started with API Extension Building

I've been using AshJsonApi pretty much since I started with Ash. My goal was to make some improvements to it and continue on. Long story short, I'm integrating with a... let's just call it "legacy" system and for a number of reasons—some sensible, some not—I'm going to need APIs that better resemble the existing infrastructure. I can't even really call these a "standard" so much as... I don't even know. Additionally, there's a team here looking to standardize internal service communication using gRPC....

Custom auth pages

Is there a simple example of custom auth pages for the AshAuth package. It's very hard trying to figure it out from the deps folder as those pages are components and configs upon components and configs. What i specifically want is to understand how can i control the magic link page to show a "Your email has been sent" message instead of the form. But at the moment it returns to the home page "/" ...
Solution:
It does submit using trigger_submit
No description

Ash query with 1 filter performs worse than the same Ecto query

We've noticed quite bad performance when querying data produced by paper_trail using Ash. The same kind of queries made with regular Ecto.Query perform much better. The tables involved are huge (it's paper trail after all), but the column by which we filter is indexed. Upon examining the difference between the produced queries, the only difference I see is in the WHERE clause: ...

Can reads return anything?

I have a search action that needs to return an array of tuples consisting of a resource reference and an atom that conveys why the resource was found by the search. There is only one type of resource involved so the action fits nicely in the resource. Can this be a read action or should it be generic?
Solution:
read actions always return lists of records pertaining to the resource

AshAuthentication with an already existing auth flow

I'm integrating Ash with a system that already has an authentication workflow. It's a passwordless flow that sends an OTP to the user's email and then generates a token for them, assuming everything checks out. I see that many Ash libraries integrate nicely with AshAuthentication. I noticed in the documentation that there's a method to integrate custom strategies. However, as I'm new to this, I'm having trouble fully understanding the documentation. The link can be found here: https://hexdocs.pm/ash_authentication/custom-strategy.html Can I integrate our existing auth flow into AshAuthentication using the custom strategy model? These OTPs are used for registration, verifying the user before updating certain information (e.g., updating their email), verifying their new email, and logging in. If it's possible, I'd like to integrate it to benefit from using it. I'll just have to buckle down and do my best to learn. If there's an easier way to integrate while maintaining compatibility with other Ash libraries, please let me know. Ultimately, I want my authentication system to work seamlessly with all the resources and tools I add....
Solution:
Honestly, there isn't much need to integrate it as a custom strategy

Weird policy behavior

Given the following policy: ``` policy action_type(:read) do forbid_if expr(is_nil(^actor(:organization_id))) authorize_if expr(id == ^actor(:organization_id))...
Solution:
No, the way you're doing it makes sense.