frankdugan3
frankdugan3
AEAsh Elixir
Created by frankdugan3 on 6/1/2023 in #support
Calculation with arguments used in another calculation for sorting
I have a calculation that uses a postgres function to return a json object:
calculate :total_hours_report,
Hsm.Ash.Payroll.TotalHoursReport,
expr(
type(
fragment(
"get_attendance_summary(?, ?, ?)",
id,
^arg(:start_date),
^arg(:end_date)
),
^Hsm.Ash.Payroll.TotalHoursReport
)
) do
private? true
argument :start_date, :date, allow_nil?: false
argument :end_date, :date, allow_nil?: false
end
calculate :total_hours_report,
Hsm.Ash.Payroll.TotalHoursReport,
expr(
type(
fragment(
"get_attendance_summary(?, ?, ?)",
id,
^arg(:start_date),
^arg(:end_date)
),
^Hsm.Ash.Payroll.TotalHoursReport
)
) do
private? true
argument :start_date, :date, allow_nil?: false
argument :end_date, :date, allow_nil?: false
end
It produces a number of fields like total_hours etc that I'd like to sort on. I know I need to extract the field with another calculation and sort on that, but I'm getting a little hung up on how to handle calling a calculation with args inside another calculation with args. It's also a fairly expensive operation, so if possible I'd like to somehow tell it to use the already-loaded calculation and not require the arguments at all. Any pointers? :thinkies:
28 replies
AEAsh Elixir
Created by frankdugan3 on 5/22/2023 in #support
Can override `sign_in_route`, but not `reset_route` for AshAuthenticationPhoenix
No description
4 replies
AEAsh Elixir
Created by frankdugan3 on 5/13/2023 in #support
Many to Many Error
Given these relationships:
# Capability
relationships do
many_to_many :steps, Hsm.Ash.MCP.Step do
through Hsm.Ash.MCP.StepCapability
source_attribute_on_join_resource :capability_id
destination_attribute_on_join_resource :step_id
end
end

# Step
relationships do
many_to_many :capabilities, Hsm.Ash.Workcenters.Capability do
through Hsm.Ash.MCP.StepCapability
source_attribute_on_join_resource :step_id
destination_attribute_on_join_resource :capability_id
end
end

# StepCapability
relationships do
belongs_to :capability, Hsm.Ash.Workcenters.Capability,
allow_nil?: false,
api: Hsm.Ash.Workcenters
belongs_to :step, Hsm.Ash.MCP.Step, allow_nil?: false, api: Hsm.Ash.MCP
end
# Capability
relationships do
many_to_many :steps, Hsm.Ash.MCP.Step do
through Hsm.Ash.MCP.StepCapability
source_attribute_on_join_resource :capability_id
destination_attribute_on_join_resource :step_id
end
end

# Step
relationships do
many_to_many :capabilities, Hsm.Ash.Workcenters.Capability do
through Hsm.Ash.MCP.StepCapability
source_attribute_on_join_resource :step_id
destination_attribute_on_join_resource :capability_id
end
end

# StepCapability
relationships do
belongs_to :capability, Hsm.Ash.Workcenters.Capability,
allow_nil?: false,
api: Hsm.Ash.Workcenters
belongs_to :step, Hsm.Ash.MCP.Step, allow_nil?: false, api: Hsm.Ash.MCP
end
All of them are in the same API and Registry. I'm getting an error that I don't quite understand (join_relationship_name???):
** (EXIT from #PID<0.96.0>) an exception was raised:
** (RuntimeError) Resource `Hsm.Ash.MCP.StepCapability` is not in registry `Hsm.Ash.Workcenters.Registry` for autogenerated join relationship: `:steps_join_assoc`

Relationship was generated by the `many_to_many` relationship `:steps`

If the `through` resource `Hsm.Ash.MCP.StepCapability` is not accepted by the same
api as the destination resource `Hsm.Ash.MCP.Step`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:

has_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
# configure the relationship attributes
...
end

You can use a name other than `:steps_join_assoc`, but if you do, make sure to
add that to `:steps`, i.e

many_to_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
...
join_relationship_name :your_new_name
end

(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:43: anonymous fn/5 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
(elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:16: anonymous fn/4 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
(elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:15: Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
lib/hsm/ash/workcenters/registry.ex:1: anonymous fn/1 in Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1
(elixir 1.14.4) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
lib/hsm/ash/workcenters/registry.ex:1: Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1
** (EXIT from #PID<0.96.0>) an exception was raised:
** (RuntimeError) Resource `Hsm.Ash.MCP.StepCapability` is not in registry `Hsm.Ash.Workcenters.Registry` for autogenerated join relationship: `:steps_join_assoc`

Relationship was generated by the `many_to_many` relationship `:steps`

If the `through` resource `Hsm.Ash.MCP.StepCapability` is not accepted by the same
api as the destination resource `Hsm.Ash.MCP.Step`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:

has_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
# configure the relationship attributes
...
end

You can use a name other than `:steps_join_assoc`, but if you do, make sure to
add that to `:steps`, i.e

many_to_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
...
join_relationship_name :your_new_name
end

(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:43: anonymous fn/5 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
(elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:16: anonymous fn/4 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
(elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:15: Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
lib/hsm/ash/workcenters/registry.ex:1: anonymous fn/1 in Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1
(elixir 1.14.4) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
lib/hsm/ash/workcenters/registry.ex:1: Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1
I'm probably missing something obvious, but I can't spot it.
32 replies
AEAsh Elixir
Created by frankdugan3 on 4/21/2023 in #support
Multi-Location + Multi-Tenant Read Replica
No description
4 replies
AEAsh Elixir
Created by frankdugan3 on 3/30/2023 in #support
Better way to do this query?
I have a simple search action for an autocomplete, and I want to have it skip the filter if the search term is "" in order to just return the top sorted options. I have a pretty simple solution, but was wondering if there's a cleaner/more idiomatic way of doing it:
read :autocomplete do
argument :search, :ci_string

prepare fn query, _ ->
search_string = Ash.Query.get_argument(query, :search)

query
|> Ash.Query.filter(
if ^search_string != "", do: contains(name_email, ^search_string), else: true
)
|> Ash.Query.load(:name_email)
|> Ash.Query.sort(:name_email)
|> Ash.Query.limit(10)
end
end
read :autocomplete do
argument :search, :ci_string

prepare fn query, _ ->
search_string = Ash.Query.get_argument(query, :search)

query
|> Ash.Query.filter(
if ^search_string != "", do: contains(name_email, ^search_string), else: true
)
|> Ash.Query.load(:name_email)
|> Ash.Query.sort(:name_email)
|> Ash.Query.limit(10)
end
end
If not, no problem, this works fine. 🙂
18 replies
AEAsh Elixir
Created by frankdugan3 on 3/23/2023 in #support
ashauthentication: possible bugs?
I have a couple errors coming up with AshAuthentication, not sure if they're bugs or me doing something wrong. 1) If I disable registration:
strategies do
password :password do
identity_field :email
registration_enabled? false
strategies do
password :password do
identity_field :email
registration_enabled? false
I get this error:
[error] #PID<0.22797.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.22796.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (KeyError) key :type not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
(ash_phoenix 1.2.10) lib/ash_phoenix/form/form.ex:396: AshPhoenix.Form.for_action/3
(ash_authentication_phoenix 1.6.4) lib/ash_authentication_phoenix/components/password/register_form.ex:59: AshAuthentication.Phoenix.Components.Password.RegisterForm.update/2
(phoenix_live_view 0.18.18) lib/phoenix_live_view/utils.ex:484: Phoenix.LiveView.Utils.maybe_call_update!/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:661: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(stdlib 4.2) maps.erl:411: :maps.fold_1/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:635: Phoenix.LiveView.Diff.render_pending_components/6
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:146: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.2) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint.plug_builder_call/2
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint."call (overridable 3)"/2
(hsm 0.8.0) lib/plug/debugger.ex:136: HsmWeb.Endpoint."call (overridable 4)"/2
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint.call/2
(phoenix 1.7.2) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
(cowboy 2.9.0) /home/frank/git/hsm-tmp-release-branch/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.9.0) /home/frank/git/hsm-tmp-release-branch/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
[error] #PID<0.22797.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.22796.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /sign-in
** (exit) an exception was raised:
** (KeyError) key :type not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
(ash_phoenix 1.2.10) lib/ash_phoenix/form/form.ex:396: AshPhoenix.Form.for_action/3
(ash_authentication_phoenix 1.6.4) lib/ash_authentication_phoenix/components/password/register_form.ex:59: AshAuthentication.Phoenix.Components.Password.RegisterForm.update/2
(phoenix_live_view 0.18.18) lib/phoenix_live_view/utils.ex:484: Phoenix.LiveView.Utils.maybe_call_update!/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:661: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(stdlib 4.2) maps.erl:411: :maps.fold_1/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:635: Phoenix.LiveView.Diff.render_pending_components/6
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:146: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.2) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint.plug_builder_call/2
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint."call (overridable 3)"/2
(hsm 0.8.0) lib/plug/debugger.ex:136: HsmWeb.Endpoint."call (overridable 4)"/2
(hsm 0.8.0) lib/hsm_web/endpoint.ex:1: HsmWeb.Endpoint.call/2
(phoenix 1.7.2) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
(cowboy 2.9.0) /home/frank/git/hsm-tmp-release-branch/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.9.0) /home/frank/git/hsm-tmp-release-branch/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
2) When I try to open a password reset link, I get the following error:
67 replies
AEAsh Elixir
Created by frankdugan3 on 2/3/2023 in #showcase
WIP (pre-alpha) Ash UI Extension & Component Lib
No description
86 replies