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

--install igniter option clarification

Is passing --install foo,bar --install baz,quux equivalent to --install foo,bar,baz,quux?
Solution:
yes

Enforce each item is unique in attribute array

Hi, is there a way to set a constraint on this array attribute, that enforces each item to be unique? For example it should not allow [:en, :en] . ```...

Use policies to limit allowed values of Enum in create action

This is a follow-up to my question yesterday. Again, I have this Enum: ```elixir defmodule Dreng.Accounts.Role do use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand] end...
Solution:
Give the SimpleCheck a go and let us know if it helps

what is the possiblity that ash code gen does not generate migration

what is the possiblity that ash code gen does not generate migration and reporting migrations already up, I have new resources, but it is not generating migrations

newbie: incorrect code in AshPostgres examples?

https://hexdocs.pm/ash_postgres/get-started-with-ash-postgres.html#aggregates the last example there is about loading aggregates on demand, and includes in particular: ```elixir representatives = Helpdesk.Support.read!(Helpdesk.Support.Representative)...
Solution:
Just to add that you can have code_interfaces on your domain, that have functions you can call. But in that case you won't need to pass the Resource. https://hexdocs.pm/ash/code-interfaces.html

How to access property of a join resource in filter?

I have 2 resources in a many to many relationship through a 3rd join resource. However, this join resource has an additional boolean column. So now when I'm doing a filter, how do I select only those related resources whose boolean is true or false in the join_through resource?
Solution:
Nvm figured it out. Apparently this was exactly what the parent() expression is for https://hexdocs.pm/ash/expressions.html#many-to-many-relationships. I didn't know I had to give a custom name to my join_relationship or otherwise use the default _join_assoc name when accessing this field

error in creating new project

below is the command mix igniter.new it_toolbox_backend --with phx.new --install ash,ash_phoenix --install ash_graphql,ash_json_api --install ash_postgres,ash_authentication --install ash_authentication_phoenix,ash_csv --install ash_admin,ash_oban --install oban_web,ash_state_machine --install ash_events,ash_money --install ash_double_entry,ash_archival --install live_debugger,mishka_chelekom --install ash_paper_trail,cloak --install ash_cloak --auth-strategy password --auth-strategy magic_link --auth-strategy api_key --yes below is the output * creating......

Custom queries in migration

I want to execute some custom queries in my postgres migration to populate a new table. Does Ash postgres support a way to do this, or should I just edit the generated migration files?
Solution:
But editing the migration is perfectly reasonable for data migrations

Potential bug with relationship `parent` references

Bit of a gnarly one ahead... 😅 I'm running onto what I think is a bug with parent in relationship filters. My setup looks something like this: 1. A resource called GuideLevel with a has_many relationship with no_attributes? true and a filter. This relationship is called ancestors and uses an AshPostgres.Ltree column to get the ancestors of the current record, although idt the ltree behavior is relevant to the bug. The filter expression looks like: filter expr(fragment("? @> ? AND ? < ?", level, parent(level), nlevel, parent(nlevel))). Note that this references an nlevel calculation which just calculates the nlevel of the ltree column: calculate :nlevel, :integer, expr(fragment("nlevel(?)", level))...
Solution:
@Jesse Williams thanks for the tests, I've got a fix

Testing `Ash.Resource.Change` in Isolation

I'm starting to break up my resources into separate modules using Ash.Resource.Change and it's occurring to me it shouldn't be too difficult to test those modules in isolation. If I have an Ash.Resource.Change that just runs an after_transaction hook, how do I trigger that function directly?...
Solution:
At that point I might just make the function you pass to after_action a public function on the module and test that. At least I don't know of a good way to trigger the after action without running the whole action

Accept subset of Ash.Type.Enum in action

I have an Ash.Type.Enum defined as ```elixir defmodule Dreng.Accounts.Role do use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand] end...
Solution:

Update Params in Nested Form with Union type

I have a code snippet that looks as follows: ```elixir def update_subform_field(root_form, subform_name, new_value) do AshPhoenix.Form.update_form(root_form, subform_name, fn sub_form ->...

Ash.Error.Unknown.UnknownError: Invalid reference

I have this action in the UserUpload resource. I added another criteria for filtering the resource by the first or last name of its user relationship. However, the String.contains? lines give this error:
11:29:38.679 request_id=GFIrFgeBN9WstPIAASCB remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Unknown{errors: [%Ash.Error.Unknown.UnknownError{error: "Invalid reference user.first_name at relationship_path [:user]", field: nil, value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :unknown}]}}
11:29:38.679 request_id=GFIrFgeBN9WstPIAASCB remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Unknown{errors: [%Ash.Error.Unknown.UnknownError{error: "Invalid reference user.first_name at relationship_path [:user]", field: nil, value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:filter], stacktrace: #Splode.Stacktrace<>, class: :unknown}]}}
The relationship and its first_name and last_name fields are public?: true...
No description

Advise on using policies with related resources

I have two resources Transfer and Account. Transfer updates the accounts balance it's related to. Now I have admin which can create/update/read both resources. I have an operator that can only create transfers. The issue is updating the account balance when the operator creates the transfer. Since he does not have access to create/update an acccount....

AshCommanded - I'm running in to an issue with ash_commanded not working with spark v3?

Heyo! Long time follower, but first time poster. I'm just kind of curious about the ash_commanded project and if anyone is using it? It seems like it might be dead which is surprising to me considering how popular commanded project seems to be....

How to set the actor within an action

Hey everyone! Currently, we have an action that takes a user as an argument: ``` create :upsert_meeting_prep_action do...

Subscriptions do not work when declared in the domain.

Subscriptions work when declared in the Resource like this: ```elixir defmodule JoseValimIsMyHero.Accounts.User do use Ash.Resource,...

Plug.CSRFProtection.InvalidCSRFTokenError

Is there some documentation I can refer to about handling CSRF error for email confirmation using Ash Authentication. Clicking on the Confirm button on the confirmation email gets me this error. Plug.CSRFProtection.InvalidCSRFTokenError at POST /auth/user/confirm invalid CSRF (Cross Site Request Forgery) token, please make sure that: ...

Rollback went further than expected

Did I do this incorrectly? I ran mix ash.rollback -r Ngen.Repo and answered the prompt but it rolled much further back than I expected. ```bash How many migrations should be rolled back? (default: 0) ...

Persisting values from relationships at creation time

Hi there! I'm working on a demo that allows products to be purchased by users. Since prices might change over time, I'd like to put the price of the product at the time of purchase into the order resource record. Given a product with the following attributes...
Solution:
``` change before_action(fn changeset, context -> product_id = Ash.Changeset.get_attribute(changeset, :product_id) product = AppName.DomainName.get_product!(product_id, actor: context.actor) ...