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

manage_relationship argument not relating primary key to resource

resource ``` create :add_to_group do argument :group, :uuid do allow_nil? false...

Calculations Using Relationships

I'm writing a simple chat app to try to learn Ash. I have models like below and I'd like to write an :unread_count calculation on the Channel. It would take the current user as the actor and find the associated member of the channel, use that :last_read_at time to filter down the messages associated with the channel to ones that has a :created_at after that time, and count them. I'm having a hard time figuring out how to do that based on the examples. What I think I want is something like:...

Ash Admin dependency for newest liveview

Because your app depends on ash_admin ~> 0.8.1 which depends on phoenix_live_view ~> 0.18.3, phoenix_live_view ~> 0.18.3 is required.
So, because your app depends on phoenix_live_view ~> 0.19.0, version solving failed.
Because your app depends on ash_admin ~> 0.8.1 which depends on phoenix_live_view ~> 0.18.3, phoenix_live_view ~> 0.18.3 is required.
So, because your app depends on phoenix_live_view ~> 0.19.0, version solving failed.
Anyway to solve this? or have to wait for update? create an issue?...

Ambiguous Call during Compile because of Extension

I'm creating an extension and I tried adding an actions option to it, but it won't compile the resources anymore because it cant tell which actions function to use. ``` == Compilation error in file test/support/policy.ex == ** (CompileError) test/support/policy.ex:52: function actions/1 imported from both Demo.Extensions.Rbac.Rbac.Role.Options and Ash.Resource.Dsl, call is ambiguous...

How not to select fields when loading a resource

Is there a way in Ash to not select a field when loading a resource? We have some fields in the DB that are really large and we don't need to select them most of the time. Is there a way to tell Ash not to select that field for this particular load or action?...

How to put the same value at multiple places in a fragment?

Say I have a custom postgres function and Is it possible to do the following fragment fragment("SELECT my_custom_function(1/<rate>, 2/<rate>, 3*<rate>) FROM lookup_values WHERE id=<id>", rate, id)? Today, I will need to do fragment("SELECT my_custom_function(1/?, 2/?, 3*?) FROM lookup_values WHERE id=?", rate, rate, rate, id)...

How do you sort by substring?

Current in my resource ```actions do defaults [:read] read :list do...

Actor not passed to `read` action after `create` action

I have a resource with a default :create action and :read action, and an AshGraphql mutation that calls :create. The resource has a module-based policy that requires the actor have a certain "role". When I test the mutation, the policy allows the actor to perform the :create, but when it checks the :read action that happens at the end of the mutation, the actor passed to the policy is nil. What makes this especially confusing is that I have other resources that are set up the same way, and they don't have this nil actor problem. I'll post my code in the comments below....

Manual relationship with recursive CTE

I'm trying to implement this comment/thread (https://discord.com/channels/711271361523351632/1110614023881359430/1111297127897890866) and creating a manual relationship with a recursive CTE (for a tag in a graph structure, get all parent tags). I'm able to get it done with Ecto spitting out grouped map lists. I'm getting a bit stuck figuring out how to get them as an Ash Resource in the end. Is there anything major I'm missing? ```elixir...

action argument default to another argument?

Trying to use the value passed in one argument as a default value for a second argument. Is there a way? Something like: ```elixir create :new_record do primary? true argument :short_name, :string, allow_nil?: false...

Possible to use relationships for Identity?

```elixir defmodule One.Exam.QuestionParagraph do use Ash.Resource, data_layer: AshPostgres.DataLayer ...

How should module calculations return errors?

Since the name of the function calculate/3 doesn’t end with ! and returns a raw value instead of an ok/error tuple, I’m just checking whether it’s OK for my custom calculation (defined in its own module) to raise an error which can be caused by, say, an attribute having a value of an unexpected type or an invalid string format (this would be caused by a bug in the app — I’m not trying to code a validation in a calculation).

Broadcasting pubsub update notifications only if the resource has been changed?

At the moment a broadcast is made after the action is successfully performed - even if nothing on the record actually changed. My scenario is having a background worker that checks validity of some credentials in a loop periodically, in an action like so: ```elixir...

Ash.Query.load not loading nested relationship?

```User |> Ash.Query.load([friendships: [:first, :second]]) |> Accounts.read!() #Ash.Query< resource: User,...

How best to model partial updates of optional attributes?

The classic example is a "user settings" page, where if they only change their username but leave the password field blank, you want to not update the password, but instead ignore it. The best I can come up with is something like this: ```elixir...

Polymorphic Self References

Can't seem to figure out how to accomplish the following. I have a polymorphic table that is meant to model a tree relationship. this of course requires a belongs_to and has_many relationship to itself. How do I go about defining a self referential relationship that is mean to pickup on context provided by the consumer? Such that all the relationships are within the same table? ```...

How to create a second resource on a create action?

what is the best way yo create a second resource durning the creation of a first one? for example in a Workspace resource that should have a Wallet resource as has_one relationship...

How to set belongs_to on in a form

I have a create action for Plan that sets the Product (Plan belongs_to Product) ```elixir create :create do primary? true...

Policy authorizer not applying to read action

I have this policy ``` policies do policy always() do authorize_if action(:create)...

How to pass args to Api.read

I'm trying to accomplish something like this
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
for an action that looks like this ```read :list do...