Filtering by/selecting calculations when working with direct ecto queries
I have a use case where I'm needing to reach for Ecto directly. I'm trying to see if it's possible to filter by a calculation (or even just select it) when doing this. I can of course duplicate my calculation logic, but looking for a way to avoid that if possible 😅
Solution:
Nope 😄
After-commit hook?
I'm running into a race condition issue when I insert a row to a table with the resource's create action, and the subscriber to the notification calculates the resulting row count. What's the right way to do this in Ash? Adding 'Process.sleep(1000)' seems to help but I'm hoping there is a better way. Thanks.
soft delete - identity issue
i have a resource, for which soft delete is on, the resource has a field: :deleted_at.
If I do not add this field to the identity, on creation the data is validated to be unique, but if I (soft) delete a record, than I can not create another one with the same unique fields.
If I add the field to the identity, on creation the data is not validated correctly, since it includes the deleted_at null field....
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
nested form issue
Hi Guys!
I am trying to apply a simple nested form, and I can not get through.
The use-case is simple: I want to add supplier_prices to my users. I tried to do everything according to the docs, probably missed something....
Rendering AshPaperTrails
Solution:
In my Member ressource, I have:
```paper_trail do
primary_key_type :uuid
only_when_changed? true
change_tracking_mode :changes_only...
`: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?...
Solution:
Yeah, that would work. You could also see what happens if you do this:
```elixir
has_many :last_ten... do
read_action :an_action_with_a_limit...
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...
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?...