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

Redirect on successful authentication

This seems like a trivial issue but I can't seem to figure out how to do it. Suppose: 1. A user clicks the account button in the navbar but is currently logged out. 2. Ash authentication helpers redirect them to /sign-in. 3. They log in successfully....

How to implement Authentication with Multiple OAuth2 Providers?

I have have already implemented email/password auth and now I want to add OAuth2 login with multiple providers (Google and Facebook). I saw the guide for Google, but not sure how to set up multiple providers together.

Is It Possible to Track Create and Update Operations at the Domain Level for AshOban?

Hi, sorry, Is it possible to track create and update operations at the domain level of all resources under this domain, so that whenever such actions occur, their information is sent to AshOban for further processing? Something like ```elixir...
Solution:
Yeah nothing builtin to help you do that. Your best bet is likely to have custom Oban jobs for the compilation you want to do and then to use global changes to start those jobs in the same transaction on each resource.

Upsert with ON CONFLICT DO NOTHING

Is it possible to configure an upsert to do ON CONFLICT DO NOTHING?
Solution:
Yeah that would likely do it 🙂

Ash update action inside Ecto transaction, trying to not rollback if transaction is rolled back

I have a validation that (probably?) happens in a transaction outside of Ash, and I'd like to run an Ash action if validation fails. But right now when the transaction is rolled back my Ash update action is being rolled back too, even if wrapped in a new Ash.DataLayer.transaction. Any ideas how I could have it not be rolled back?

How can I show all validation errors (including nested) at once?

I'm using manage_relationship/4 in a top-level action that accepts nested fields via arguments. Right now, the nested validation errors only show after the top-level data is valid. Is there a way to surface all validation errors (parent + nested) simultaneously? I'd like users to see everything in one go
Solution:
If you have time to make a PR, what needs to happen is something like this: ```elixir form |> AshPhoenix.Form.raw_errors(for_path: :all)...

Do you have special settings for Credo for Ash projects?

I just added Credo to a project that is getting big, the amount of fixes are huge, a good part of it due to automatic code generations. The gepeto suggest: ```elixir...

Losing entries for nested forms on validate

To reproduce: - Have form for update action with manage_relationship(:resource, type: :direct_control). - Have a button to add new form: ``` def handle_event("add-form", %{"path" => path}, socket) do...
Solution:
I think you're missing pattern matching the actual params out

AshAuthentication with non-Postgres Data Layers?

I am writing a small "microservice" which takes a JSON post from an internal system and does a side effect (i.e. validates it, processes it based on if CAD drawings in a directory exist or not, then leaves a custom CSV in a directory being watched by vendor software). I have it working without Ash (just using OpenAPISpex and phx gen.auth api keys) but I need to rewrite it so the release will run as a Windows Service for performance reasons (don't ask!! 😰) and thought this would be a great very easy way to start learning some Ash resources, actions, and json_api at least on a simple easy project! The API and side effect generating stuff works great (simple/embedded data layer) I just need to add api key authentication so I added AshAuthentication. Looking at the code it seems agnostic to the data layer but every example online all assumes AshPostgres and this may be the only way to get it to work. This service is not publicly-accessible and of course HTTPS is used but I still want some sort of key to be checked even if the hash is stored in an env var and read by runtime config then checked. Or in SQLite data layer or a JSON/CSV file or something. I just don't want to add the complexity of adding PGSQL on Windows to this simple deployment....

AshJsonAPI - How to pass a tenant?

I am running curl commands against my AshJsonAPI endpoint and, as expected, I receive a 'tenant must be set' error as I am not passing the tenant.
curl -XPOST -H 'Content-Type: application/vnd.api+json' localhost:4000/api/json/items -d '{"data": {"type": "item", "attributes": {"name": "test", "provider_id": "01985d4d-f0c4-73b5-8919-29946afeb08c", "deploys": []}}}'
curl -XPOST -H 'Content-Type: application/vnd.api+json' localhost:4000/api/json/items -d '{"data": {"type": "item", "attributes": {"name": "test", "provider_id": "01985d4d-f0c4-73b5-8919-29946afeb08c", "deploys": []}}}'
...

How to use Heroicons?

Hi everyone, I have a brand new Ash project and have the following import in mix.exs: ``` {:heroicons, github: "tailwindlabs/heroicons",...
Solution:
I just had to read the docs!! :p https://hexdocs.pm/heroicons/Heroicons.html...

Error tenant required in calculation on tenant resource

Hello! I'm getting an error I don't really know how to solve. It might be a dumb error from my side. I'm trying to count the number of rows of a resource inside a tenant (the 'items' table) and have it as a calculation on my tenant (the 'project' resource). This way I can know from the outside of the multi-tenancy world how many items are inside a project....

Convenience functions for many_to_many relationships?

I'm trying to wrap my head around creating convenience functions for many_to_many relationships. Given the resources below, what I'd like to do is have an add_to_hub action in the User module that takes in a Hub record and creates a corresponding UsersToHubs record. How would I go about setting up that action, and is placing a function like this inside of my User resource module at all idiomatic for Ash? I cut off the TestApp.Hubs.Hub module due to character limit, but I set it up the same way as my User module...
Solution:
I appreciate the very kind "read the manual" haha. Definitely overlooked the many_to_many example when I was reading the docs earlier. So it's basically just: ```elixir update :assign_to_hub do...

Is it possible to prevent any direct use of Ash resource?

Hi sorry i could not this in document, I want to create a policy (not ash policy) to notice developers!! they just must call domain and any query with resource in out of resource for example in LiveView is forbidden! is there any option? it is like create boundary Thank you in advance...
Solution:
No, there is no real way to prevent directly calling the resource.

Form vs simple_form

Hi guys, I see that in the Ash Framework book forms are based on simple_form but when using Ash phoenix liveview generators, the regular form is used by default. Is there a reason to use one vs the other? I incline to follow what the book does but I want to make sure this is the right decision.
Solution:
I'd also trust the book over the generators.

Global hooks

Is there any mechanism to run a before hook for any action of any resource? I have a tenant that is an org, and an actor that is a membership. Membership also has a team association I want to load in the context of any action....

Using add_form with a many_to_many relationship

Trying to use add_form on a many_to_many relationship. Here is my action and relationship. ```elixir create :create_campaign_target_list do primary? true...

🔹 How to Regenerate a Specific Resource Using `ash.codegen` Without Affecting Others?

Hi, I've read the ash.codegen (https://hexdocs.pm/ash/Mix.Tasks.Ash.Codegen.html) documentation but couldn't find an option related to this. I'm still in the early stages of development and sometimes make mistakes while defining resources (e.g. when generating multiple tables). When that happens, I want to regenerate just a specific resource from scratch, not create a new migration to fix it. However, ash.codegen seems to regenerate all active resources at once. To avoid that, I have to manually remove the files of the resource I want to regenerate and then run the generator again. ...
Solution:
I don't think so. migrations are for one version of your database to the next. your app won't run if your migrations are incomplete and your resources don't match your database

Subscription to automated resource creation

I have a question regarding subscriptions. I've set up subscriptions in my application and I have one subscription endpoint that works perfectly. I have a 2nd one that isn't working at all. However, the 2nd one monitors a resource that is created in an automated way from the backend by an ash notifier when a different resource is created. Example: Let's pretend we have a Message Resource and an Alert Resource. We have a Ash.Notifier that on create checks if the message has the keyword "foo". If it is, we create an Alert . If I have a subscription to the Alert resource, should I expect that subscription to work even though it wasn't created from the frontend? I would assume yes but that is not what I'm experiencing....

mark Ash.Resource extension attributes as public

Other than redefining the extension attributes in my own resource, is there a better way?
extensions: [AshDoubleEntry.Transfer, AshGraphql.Resource]
extensions: [AshDoubleEntry.Transfer, AshGraphql.Resource]
...
Solution:
🤔 you could write your own extension that would mark amount as public after AshDoubleEntry.Transfer creates it