Aggregates based on resources keep failing
defmodule YourApp.Poetry.Topic do
alias YourApp.Poetry.Poem
use Ash.Resource,
domain: YourApp.Poetry,
data_layer: AshPostgres.DataLayer
require Ash.Query
postgres do
table "topics"
repo YourApp.Repo
end
actions do
defaults [:create, :read, :update, :destroy]
end
attributes do
uuid_v7_primary_key :id
attribute :name, :string, allow_nil?: false
attribute :slug, :string
attribute :description, :string
timestamps()
end
aggregates do
# count :verse_count, :verses
count :poem_count, Poem do
filter expr(fragment("? = ANY(topics)", parent(name)))
end
end
identities do
identity :unique_name, [:name]
identity :unique_slug, [:slug]
end
end
defmodule YourApp.Poetry.Topic do
alias YourApp.Poetry.Poem
use Ash.Resource,
domain: YourApp.Poetry,
data_layer: AshPostgres.DataLayer
require Ash.Query
postgres do
table "topics"
repo YourApp.Repo
end
actions do
defaults [:create, :read, :update, :destroy]
end
attributes do
uuid_v7_primary_key :id
attribute :name, :string, allow_nil?: false
attribute :slug, :string
attribute :description, :string
timestamps()
end
aggregates do
# count :verse_count, :verses
count :poem_count, Poem do
filter expr(fragment("? = ANY(topics)", parent(name)))
end
end
identities do
identity :unique_name, [:name]
identity :unique_slug, [:slug]
end
end
3 Replies
[error] Process #PID<0.885121.0> raised an exception
** (Spark.Error.DslError) [YourApp.Poetry.Topic]
aggregates -> poem_count:
relationship referenced in aggregate `YourApp.Poetry.Topic.Elixir.YourApp.Poetry.Poem` does not exist
(elixir 1.18.4) lib/process.ex:896: Process.info/2
(spark 2.2.67) lib/spark/error/dsl_error.ex:30: Spark.Error.DslError.exception/1
(ash 3.5.33) lib/ash/resource/verifiers/validate_aggregates_supported.ex:29: Ash.Resource.Verifiers.ValidateAggregatesSupported.check_aggregatable/4
(elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(ash 3.5.33) lib/ash/resource/verifiers/validate_aggregates_supported.ex:16: Ash.Resource.Verifiers.ValidateAggregatesSupported.verify/1
lib/your_app/poetry/topic.ex:1: anonymous fn/1 in YourApp.Poetry.Topic.__verify_spark_dsl__/1
(elixir 1.18.4) lib/enum.ex:4442: Enum.flat_map_list/2
lib/your_app/poetry/topic.ex:1: YourApp.Poetry.Topic.__verify_spark_dsl__/1
(elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(elixir 1.18.4) lib/module/parallel_checker.ex:244: Module.ParallelChecker.check_module/3
(elixir 1.18.4) lib/module/parallel_checker.ex:90: anonymous fn/7 in Module.ParallelChecker.inner_spawn/6
** (EXIT from #PID<0.882154.0>) shell process exited with reason: an exception was raised:
** (Spark.Error.DslError) [YourApp.Poetry.Topic]
[error] Process #PID<0.885121.0> raised an exception
** (Spark.Error.DslError) [YourApp.Poetry.Topic]
aggregates -> poem_count:
relationship referenced in aggregate `YourApp.Poetry.Topic.Elixir.YourApp.Poetry.Poem` does not exist
(elixir 1.18.4) lib/process.ex:896: Process.info/2
(spark 2.2.67) lib/spark/error/dsl_error.ex:30: Spark.Error.DslError.exception/1
(ash 3.5.33) lib/ash/resource/verifiers/validate_aggregates_supported.ex:29: Ash.Resource.Verifiers.ValidateAggregatesSupported.check_aggregatable/4
(elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(ash 3.5.33) lib/ash/resource/verifiers/validate_aggregates_supported.ex:16: Ash.Resource.Verifiers.ValidateAggregatesSupported.verify/1
lib/your_app/poetry/topic.ex:1: anonymous fn/1 in YourApp.Poetry.Topic.__verify_spark_dsl__/1
(elixir 1.18.4) lib/enum.ex:4442: Enum.flat_map_list/2
lib/your_app/poetry/topic.ex:1: YourApp.Poetry.Topic.__verify_spark_dsl__/1
(elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(elixir 1.18.4) lib/module/parallel_checker.ex:244: Module.ParallelChecker.check_module/3
(elixir 1.18.4) lib/module/parallel_checker.ex:90: anonymous fn/7 in Module.ParallelChecker.inner_spawn/6
** (EXIT from #PID<0.882154.0>) shell process exited with reason: an exception was raised:
** (Spark.Error.DslError) [YourApp.Poetry.Topic]
Can you try upgrading your version of Ash?
It looks like that functionality was added in 3.5.35
thank you that solved the issue I updated both ash and ash_postgres