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

Ltree documentation?

Is there any documentation I'm not finding on how to use ltrees with Ash effectively? Found myself doing something a lot like https://hexdocs.pm/ash_postgres/manual-relationships.html#recursive-relationships, and it recommends using Ltrees instead, but I'm not quite sure where to start. Only reference I'm seeing is https://hexdocs.pm/ash_postgres/AshPostgres.Ltree.html - is there something else?
Solution:
I'd see the postgres docs

inputs_for with an array of typed_struct

I have a resource with an attribute, that is a list of typed_structs `` attributes do attribute :schedules, {:array, Schedule} end...
Solution:
Thanks for your answer! ❤️ Good to know, so i don't run in the wrong direction here. I'll use an Embedded Resource instead. This should work with inputs_for in the LiveView. ```...

How do I call an action with a predetermined argument from a code interface?

I'm creating a personal project with AshDoubleEntry, and I want to create a code interface on the Ledger domain to get an Account with a specific identifier. I currently have the following, but I'm not sure what to do to further? How do i define this hardcoded argument? ```elixir...

Can't sign into Ash Phoenix Auth with Chris McCord's web command

Using the web command to sign into Ash Phoenix Auth password login page does not work. (Web command: https://github.com/chrismccord/web/) ```...

Seeding relationships with `seed_generator`?

Is it possible to seed relationships inline with seed_generator? e.g. something along the lines of ```elixir...

Complex actor logic in expressions?

Since actors aren't constrained to be instances of ash resources, and in expressions, templates do simple get_in calls (link), it seems somewhat challenging to represent logic in expressions that relies on anything more than simple attributes on the actor. In some calculations I'm working on, I've resorted to representing this something like this: ```elixir @impl Ash.Resource.Calculation def expression(_opts, %{actor: actor}) do...

Does loading relationships in Embedded Resources causes N+1 query?

Question If I have an embedded resource and I want to load a relationship, using Ash.load does it creates an N+1 query problem?...

Warning(Unhandled error in form submission) when validating a form with embedded resource

I have created two embedded resources (membership_purchase and member_purchase_info). They are embedded resources just for being used in a form so I can have validations more easily. Membership_purchase can have multiple member_purchase_info. (For details, please see attachments.) ``` attribute :member_purchase_infos, {:array, Marge.AshDomains.Members.MemberPurchaseInfo}, allow_nil?: false, public?: true...
No description

Error when setting up an sqlite repo

```16:20:02.947 [info] == Running 20251101005337 Compliance.Repo.Migrations.InitializeExtensions1.up/0 forward 16:20:02.951 [info] execute "CREATE OR REPLACE FUNCTION ash_elixir_or(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE)\nAS $$ SELECT COALESCE(NULLIF($1, FALSE), $2) $$\nLANGUAGE SQL\nSET search_path = ''\nIMMUTABLE;\n" ** (Exqlite.Error) near "OR": syntax error CREATE OR REPLACE FUNCTION ash_elixir_or(left BOOLEAN, in right ANYCOMPATIBLE, out f1 ANYCOMPATIBLE)...

What is the best way to restore a version of AshPaperTrail?

I have a complex piece of code to restore a specific version of an item from AshPaperTrail, but I think I'm going down the wrong path. Take a look at the code below. ```elixir update :restore_version do accept [] require_atomic? false...

Keyword list filters on json fields

I want to understand more about keyword list filters, specifically how to filter on fragments Suppose I have a user resource with one-to-many relationship with posts. I want to count posts for each user by filtering on the post's metadata column. Something like ```...
Solution:
Figured it out. If I define a published calculation, I can use it in the keyword list, like filter: [published: "yes"]

Can not use Ash Resource action with Ash Admin without Attributes

I have defined an ash resource that represents a remote api. I have an action that makes a specific query to the API and use typed structs for the result. I'd like to be able to interact with this through ash admin. But it is giving me an error that there's no struct. This appears to be because I have no attributes on this resource. Must I declare attributes to the resource? Is there a flaw in my approach? The moment I add the following to my resource, it works fine: ```elixir attributes do...
Solution:
Short version: yes, you need to declare at least one attribute so Ash can generate a struct for your resource

AshOban scheduled action crashing Oban.Plugins.Cron

We have something like this: ```elixir oban do domain Foobar.Translations...

Authentication, Typescript and React

Hi all! I'm not sure if this thread is the best place to ask, but I have no idea where to look for more information. I’m currently migrating my Phoenix + LiveView side project to start using Ash, and everything is going smoothly. However, I’m a bit stuck regarding UI components, as there are fewer options to choose from, so I’d like to create a separate repo for a React app to speed up things a bit. I’m using ash_authentication with Google in my current app, and I have also started exploring ash_typescript and ash_json_api to generate the code needed and URLs needed for the separate React app, but I wonder what the best way is to use ash_authentication together with ash_typescript....
Solution:
All Ash components are compatible by definition. AshAuthentication provides you with data structures and the logic needed to authenticate a user. All logic is or can be exposed via a Code Interface, or any other transport (like a JSON API, or in your case, the TS integration). So in a nutshell yes, don't worry about having to roll your own auth. Won't happen...

How to do AND or OR in WHERE ?

I would like to do
validate present(:payer_member_id), where: [attribute_does_not_equal(:state, :pencil) AND attribute_does_not_equal(:state, :draft_pencil)]
validate present(:payer_member_id), where: [attribute_does_not_equal(:state, :pencil) AND attribute_does_not_equal(:state, :draft_pencil)]
or...

Ignoring a relationship on specific update actions

I have an update action that toggles just a flag on a CrewMember resource. CrewMember's have many Weapons, which are set up using change manage_relationship(:weapons, type: :direct_control). I created a new update action called set_leader, which can be called in scopes of the application where the full list of Weapons is not loaded. Is there a way to set this action to not wipe out the list of Weapons when only %{ "is_leader" => true } is passed as a param?
Solution:
that's not calling your set_leader action, that's calling the update action

scope/context is not passed to ManualRead action

Hi, just wanted to ask if this is intentional and if so, where I can find more information. I have a very simple scope like ``` scope = %MyApp.Scope{...

On-the-fly schemas/resources?

Hi! I have a rather particular use case IDK how to code in Ash. A client is asking for per-user databases, with an arbitrary number of tables and properties. Something like Notion, Supabase, or Airtable. This user generated data can change at any time, but for obvious reasons I can't recompile the whole app every time something does change. Ideally, every user should have their own little SQLite DB for their personal data, although I could be persuaded to store everything in Postgres, maybe with JSONB for simplicity. Can this be done with Ash? I know I can code the base system in it, but I can't for the life of me figure out how to handle ever-changing resources. Is this possible, or feasible?...

How do you edit migrations in regards to the generated snapshots?

With plain Ecto you can do whatever you want with old migrations as long as theyre not yet deployed, or if you don't mind wiping the database. I think this changes in regards to the snapshots that Ash generates in addition to generating the migrations. What is the recommended way of editing old migrations and keeping the generated snapshots in sync with these edited migrations?...
Solution:
You're free to edit the migration files yourself, they're generated for your convenience but it's always wise to look over them to ensure you got what you expected, as long as you also update the snapshots accordingly so that they are in sync 😄 This can be a bit tedious however, so I at least prefer to just remove the "incorrect" migrations/snapshots, and start over from the last deployed versions. One approach for getting "updated versions" if you have made some changes after generating migrations, is to delete both the migration file in question, and all the resource snapshots that was also generated when running ash.migrate. Then the previous deployed snapshot will be used as a base for diffing what has changed, and you will get an up to date migration with all the changes...

How can we restrict each user's access to a specific set of includes for an action?

How can we restrict each user's access to a specific set of includes for an action? for example public_read just can loads form and user in ash json! ```elixir json_api do type "submission"...
Solution:
you can't, that is determined by the other resource
Next