kernel
kernel
AEAsh Elixir
Created by kernel on 9/25/2023 in #support
Policy vs FieldPolicy
I haven't used FieldPolicy before, but lets say I have a :role attribute that I want to control changes to. I.e: :god should be able to create users with all roles, :admin should only be able to create :admin and :user, and :user should not be able to create any roles - but still able to edit their own account i.e: change their email etc. Would a field policy be the place for that these days?
28 replies
AEAsh Elixir
Created by kernel on 9/15/2023 in #support
Issues using Ash.Type.Union
So I'm trying to use Ash.Type.Union and I keep getting errors when attempting to load the resource, I have defined an embedded resource
defmodule VMX.Transactions.TransactionData.Type.Call do
use Ash.Resource, data_layer: :embedded

attributes do
attribute :call_uuid, :string
attribute :plivo_recording_url, :string
attribute :receiver, :string
attribute :recording_duration, :string
attribute :recording_url, :string
attribute :recording_uuid, :string
attribute :sender, :string
end
end
defmodule VMX.Transactions.TransactionData.Type.Call do
use Ash.Resource, data_layer: :embedded

attributes do
attribute :call_uuid, :string
attribute :plivo_recording_url, :string
attribute :receiver, :string
attribute :recording_duration, :string
attribute :recording_url, :string
attribute :recording_uuid, :string
attribute :sender, :string
end
end
51 replies
AEAsh Elixir
Created by kernel on 6/24/2023 in #support
pattern to use for embedded resources with variable fields?
I'm brainstorming how I'd be able to have embedded resources that have variable schemas, lets say I have a SocialMediaAccount resource, and I want an 'adapter_config' column that will be a set of config to integrate with the SocialMediaAccount, i.e: twitter api keys etc I'm going to implement an adapter pattern type thing that will include validations and a few methods to integrate with the social platform, I'm just wondering how I'd define that column in my resource? I was thinking of just using a map type - then handling validations etc in a custom change / validation?
22 replies
AEAsh Elixir
Created by kernel on 6/16/2023 in #support
manage_relationship :remove across API's
I have a Tag resource that belongs in the Organization API, I have a Transaction resource that belongs in the Transactions API, there is a join resource between them called TransactionTag that is in the Transaction API registry. I am unable to manage_relationship :remove a Tag from a Transaction resource unless I also include the TransactionTag resource in the Organization registry. (I get a ResourceNotAllowed error otherwise) Is this expected behaviour? Am I footgunning myself if I do this just because it works?
6 replies
AEAsh Elixir
Created by kernel on 6/6/2023 in #support
Few Ash.Flow questions
I've just started playing with Ash.Flow and I've got a few questions. 1) Is it possible to have a branch step with a condition like expr(Money.positive(^arg(:amount))), I've tried and get a Spark DSL error. 2) Is there a neater way to get_by a resource (similar to how we do it for code_interface) than having to define a separate action? - or does this go against the ethos of Ash.Flow, currently it seems slightly disjointed, with one part of the API encouraging one way and providing nice helpers, but another part not being really integrated, I'm assuming this is just me wanting to use it wrong and carry over certain bad habits / not knowing the magic helpers that do exist... 3) Are there plans to have a flow be able to be invoked via a code_interface? 4) Related to #2, is the input of a read step passed through to the action directly, i.e: can I pass in a load/2 as part of the input template? Or is it encouraged to just have a separate step loading the related data? 5) if I wanted to calculate some values within a Flow, I assume I'm doing it wrong? I could use a Custom step for that, but that itself seems like using the wrong tool for the job.
5 replies
AEAsh Elixir
Created by kernel on 5/9/2023 in #support
Aggregates still not working correctly
I have a few custom aggregates that have a filter on them that don't seem to work anymore.
BackOffice.Vehicle
|> Ash.Query.aggregate(:pending_jobs_today_count, :count, :jobs, filter: expr(status == "pending"))
|> BackOffice.Api.read!(tenant: "prod")
BackOffice.Vehicle
|> Ash.Query.aggregate(:pending_jobs_today_count, :count, :jobs, filter: expr(status == "pending"))
|> BackOffice.Api.read!(tenant: "prod")
generates sql that doesn't include the filter at all
SELECT v0."id", v0."name", v0."enabled", v0."registration", v0."model", v0."inserted_at", v0."updated_at", v0."deleted_at", coalesce(s1."pending_jobs_today_count"::bigint, $1::bigint)::bigint FROM "prod"."vehicles" AS v0 LEFT OUTER JOIN LATERAL (SELECT coalesce(count(sj0."id"::uuid), $2::bigint)::bigint AS "pending_jobs_today_count", sj0."vehicle_id" AS "vehicle_id" FROM "prod"."jobs" AS sj0 WHERE ((sj0."deleted_at"::timestamptz IS NULL) = $3::boolean) AND (v0."id" = sj0."vehicle_id") GROUP BY sj0."vehicle_id") AS s1 ON TRUE WHERE ((v0."deleted_at"::timestamptz IS NULL) = $4::boolean) [0, 0, true, true]
SELECT v0."id", v0."name", v0."enabled", v0."registration", v0."model", v0."inserted_at", v0."updated_at", v0."deleted_at", coalesce(s1."pending_jobs_today_count"::bigint, $1::bigint)::bigint FROM "prod"."vehicles" AS v0 LEFT OUTER JOIN LATERAL (SELECT coalesce(count(sj0."id"::uuid), $2::bigint)::bigint AS "pending_jobs_today_count", sj0."vehicle_id" AS "vehicle_id" FROM "prod"."jobs" AS sj0 WHERE ((sj0."deleted_at"::timestamptz IS NULL) = $3::boolean) AND (v0."id" = sj0."vehicle_id") GROUP BY sj0."vehicle_id") AS s1 ON TRUE WHERE ((v0."deleted_at"::timestamptz IS NULL) = $4::boolean) [0, 0, true, true]
This had worked before, but I'm assuming with the changes made to aggregates was broken
24 replies
AEAsh Elixir
Created by kernel on 2/24/2023 in #support
Auth0 and AshAuthentication
with AshAuthentication and auth0, what should I specify as the user resource attributes? like, email etc etc, what if I want different roles? i.e: admin users and normal users? can I specify a role attribute on the resource - and have that saved in auth0 somehow?
32 replies
AEAsh Elixir
Created by kernel on 2/12/2023 in #support
Another calculations query
I have 'Job' which is related to a 'Service' via another resource (not defined as a :through). I need a calculation that does something like
expr(status == ^JobStatus.completed() and order_service.service.track_weights == true and is_nil(weights)
expr(status == ^JobStatus.completed() and order_service.service.track_weights == true and is_nil(weights)
I've already defined the first aggregates, but now I'm getting an error telling me that I need to provide field type for first, so I'm assuming that something along my chain of first aggregates is not working? or am I not allowed to define an aggregate of an aggregate?
27 replies