Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

Getting the old Inspect behaviour in ash 3.5.8

The changelog for 3.5.7 states that one case use hide_inspect_fields and such to customize the Inspect output, and also that calculations and aggregates will be removed when empty. I'm on ash 3.5.8 and I see none of that in IEx (hide_inspect_fields is accepted but ignored, and I have aggregates: %{} and calculations: %{}). Is this expected in IEx? Anybody else has the same issue?...
Solution:
Yeah it's a bug will be fixed in the next release

Rendering AshPaperTrails

Is there a good way to render the change history for a resource recorded by AshPaperTrail?

`:read`ing random entry

meow! i'd like to ask a possibly dumb question. i am currently making an inspirational quotes API. i have a /api/quote endpoint with :random action which pretty much speaks for itself - returns a random quote and its author how should i correctly define my :random action? i know how to fetch a random entry using Ecto from q in "table", order_by: fragment("RANDOM()"), limit: 1, select: q. how would i do this in my action? i am using sqlite btw and here's my resource definition ```elixir use Ash.Resource, domain: App.Domain,...
Solution:
prepare build(limit: 1, sort: Ash.Sort.expr_sort(fragment("RANDOM()")))
prepare build(limit: 1, sort: Ash.Sort.expr_sort(fragment("RANDOM()")))
...

Custom Authentication Flow with AshAuthentication in Phoenix + React (Inertia.js)

Hi everyone! I've been implementing a custom authentication flow using AshAuthentication with Phoenix and React via Inertia.js. I wanted to share my approach and ask for feedback, especially regarding password reset functionality. Working Authentication Actions So far, I've successfully implemented the following actions defined by the AshAuthentication generator in my User Resource:...

Is there a way to do a 'limit' on a relationship?

My use case is eventually an aggregate, like 'count of the last 10 posts that are unpublished'. Was thinking I could get something working if I set up a relationship that was 'most recent 10 posts', and then an aggregate count on that relationship, but not seeing anything on how that'd work. Any ideas?...

Test Question

Testing AnswerOverflow
Solution:
Here is an answer.

error with keyset pagination and random sort

As the title says i'm trying to define an action that should list my posts in a random sort while using the keyset pagination. This is the action that im calling ```elixir read :list do...

Simple policy checks based with relationships

Hello, friends! So on the website documentation, we have an example of a simple policy check: ```elixir # we're inside of a module here...

How to define custom sort?

I'm trying to get started with Ash but I'm really struggling with the basics. I'm trying to do something like this: ```elixir defmodule MyResource do use Ash.Resource, data_layer: AshPostgres.DataLayer...

Please delete

Hi, I just posted this so the new user server introduction thingy goes away, thanks!

Failing to create new user: Missing JWT signing secret

Hello there! I am trying to create a user from the admin dashboard. Creation fails, and I get an error message in the console:...

read action returning a boolean

Hi, I'm trying to make a resource to represent some global boolean flags for some features in my application. I'm just having trouble figuring out how to writing an action to return a boolean. ```elixir defmodule Foo.Bar.LiveFeatureFlags do use Ash.Resource, data_layer: AshPostgres.DataLayer...

Is there a plug for setting the tenant?

I am building an app where users can belong to different organizations. I want each organization to be it's own tenant ( https://hexdocs.pm/ash/multitenancy.html ). When the user is logged in, they select a tenant, and can only have access to data from that tenant. Is there a way call set_tenant in a router plug ( similar to Ash.PlugHelpers.set_actor(user) ) so that I can globally set the current tenant, without for any queries that might need it?...

Joining this server encourages posting here :)

If you are moving to Elixir forum, probbably remove that part of the getting started checklist?

Forbid all but one field using field policies

Hello, I need to forbid Anonymous actor access to all fields but id and status. Basically it's needed for some calulcations but we don't want him to have access to any other data. So I've tried using policies like this: ```elixir field_policies do field_policy :status do authorize_if always()...

How to use Ash.Transform?

Sorry, I know this forum is archived but I think here I can get help faster than on Elixir Forum. I'm posting here the same question I've just posted there. I need to shift the time_zone of some (DateTime) attributes from a resource. Ideally, I'd like to do it right after records are loaded from db. Is it possible? How?...

Ash.Query getting started docs

I need some help to figure out how to translate Ecto queries into Ash ones. I've already read the docs, but I'm still stucked on simple "SELECT COUNT(*) FROM table" and "SELECT MIN(field) FROM table". Where do I find such explanation? Thanks in advance.

Persist embedded resources as :text instead of :map

In my app I'm using Cocktail (https://hexdocs.pm/cocktail) to manage scheduled events which I'd like to save to a text field using Cocktail.Schedule.to_i_calendar/1. What I have so far: I use an embedded schema to generate the API used in LV forms and GraphQL...

Breaking action chain in a before_action?

Problem Statement: My webhook receives at-least-once messaging from an external producer, and I want to persist these Events -- ids generated by the producer-- as an Ash Resource, such that only one instance is saved in the database (postgres), and an Oban job is only enqueued once. I've created a custom :add action with the upsert? feature, and that works great for the Event persistence -- idempotent no-ops on subsequent calls....

AshCsv calculations update

I am drafting a little beginner tutorial for Ash, and figure that AshCsv + LiveBook might be a good way of minimal setup + transparency to what has changed in "the database". I have setup a simple calculation (of a weighed average), and was expecting that once it's been loaded (Ash.Query.load([:weighed_average])) the entries would be written to the CSV file. That is not happening. My question is, what is the right way of getting calculated values back into the file? (Or is this bad practice?)...
Next