mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
A postgresql datalayer for the Ash Framework
f290ae47b8
The conditions for this issue to occur seem to be: - DataLayer is Postgres - Resource has a relates_to_actor_via policy on read - The relates_to_actor_via path includes a has_many relationship - An aggregate is loaded The following error is produced: 1) test relates to actor via has_many and with an aggregate (AshPostgres.AggregateTest) test/aggregate_test.exs:8 ** (Ash.Error.Unknown.UnknownError) ** (ArgumentError) No such entity nil found. code: |> Api.read_one!(actor: user) stacktrace: nil.spark_dsl_config() (spark 0.3.8) lib/spark/dsl/extension.ex:129: Spark.Dsl.Extension.dsl!/1 (spark 0.3.8) lib/spark/dsl/extension.ex:158: Spark.Dsl.Extension.get_persisted/3 (ash 2.5.10) lib/ash/filter/filter.ex:2986: Ash.Filter.do_hydrate_refs/2 (ash 2.5.10) lib/ash/policy/check/relates_to_actor_via.ex:3: Ash.Policy.Check.RelatesToActorVia.try_eval/2 (ash 2.5.10) lib/ash/policy/check/relates_to_actor_via.ex:3: Ash.Policy.Check.RelatesToActorVia.try_strict_check/3 (ash 2.5.10) lib/ash/policy/checker.ex:63: Ash.Policy.Checker.do_strict_check_facts/3 (ash 2.5.10) lib/ash/policy/checker.ex:88: anonymous fn/2 in Ash.Policy.Checker.strict_check_policies/3 (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3 (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3 (ash 2.5.10) lib/ash/policy/checker.ex:9: anonymous fn/2 in Ash.Policy.Checker.strict_check_facts/1 (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3 (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3 (ash 2.5.10) lib/ash/policy/authorizer.ex:790: Ash.Policy.Authorizer.do_strict_check_facts/1 (ash 2.5.10) lib/ash/policy/authorizer.ex:372: Ash.Policy.Authorizer.strict_check/2 (ash 2.5.10) lib/ash/engine/request.ex:550: Ash.Engine.Request.do_strict_check/3 (ash 2.5.10) lib/ash/engine/request.ex:518: anonymous fn/2 in Ash.Engine.Request.strict_check/2 (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3 (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3 (ash 2.5.10) lib/ash/engine/request.ex:255: Ash.Engine.Request.do_next/1 (ash 2.5.10) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1 (ash 2.5.10) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2 (ash 2.5.10) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2 (ash 2.5.10) lib/ash/engine/engine.ex:497: Ash.Engine.do_run_iteration/2 (elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3 (ash 2.5.10) lib/ash/engine/engine.ex:440: Ash.Engine.run_iteration/1 (ash 2.5.10) lib/ash/engine/engine.ex:257: Ash.Engine.run_to_completion/1 (ash 2.5.10) lib/ash/engine/engine.ex:202: Ash.Engine.do_run/2 (ash 2.5.10) lib/ash/engine/engine.ex:141: Ash.Engine.run/2 (ash 2.5.10) lib/ash/actions/read.ex:170: Ash.Actions.Read.do_run/3 (ash 2.5.10) lib/ash/actions/read.ex:90: Ash.Actions.Read.run/3 (ash 2.5.10) lib/ash/api/api.ex:1005: Ash.Api.read_one/3 (ash 2.5.10) lib/ash/api/api.ex:998: Ash.Api.read_one!/3 test/aggregate_test.exs:44: (test) |
||
---|---|---|
.github | ||
.vscode | ||
config | ||
documentation | ||
lib | ||
logos | ||
priv | ||
test | ||
test_snapshot_path | ||
.check.exs | ||
.credo.exs | ||
.formatter.exs | ||
.gitignore | ||
CHANGELOG.md | ||
LICENSE | ||
mix.exs | ||
mix.lock | ||
README.md |
AshPostgres
AshPostgres supports all the capabilities of an Ash data layer. AshPostgres is the primary Ash data layer.
Custom Predicates:
AshPostgres.Predicates.Trigram
DSL
See the DSL documentation in AshPostgres.DataLayer
for DSL documentation
Usage
Add ash_postgres
to your mix.exs
file.
{:ash_postgres, "~> 1.0"}
To use this data layer, you need to chage your Ecto Repo's from use Ecto.Repo
,
to use AshPostgres.Repo
. because AshPostgres adds functionality to Ecto Repos.
Then, configure each of your Ash.Resource
resources by adding use Ash.Resource, data_layer: AshPostgres.DataLayer
like so:
defmodule MyApp.SomeResource do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
repo MyApp.Repo
table "table_name"
end
attributes do
# ... Attribute definitions
end
end
Generating Migrations
See the documentation for Mix.Tasks.AshPostgres.GenerateMigrations
for how to generate
migrations from your resources
Contributors
Ash is made possible by its excellent community!