ash_postgres/test/polymorphism_test.exs
Zach Daniel 37cc01957d
improvement!: 3.0 (#227)
* WIP

* chore: fix mix.lock merge issues

* improvement: upgrade to 3.0

* chore: remove `repo.to_tenant`

* chore: continue removal of unnecessary helper

* chore: use `Ash.ToTenant`
2024-03-27 16:52:28 -04:00

29 lines
736 B
Elixir

defmodule AshPostgres.PolymorphismTest do
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Post, Rating}
require Ash.Query
test "you can create related data" do
Post
|> Ash.Changeset.for_create(:create, rating: %{score: 10})
|> Ash.create!()
assert [%{score: 10}] =
Rating
|> Ash.Query.set_context(%{data_layer: %{table: "post_ratings"}})
|> Ash.read!()
end
test "you can read related data" do
Post
|> Ash.Changeset.for_create(:create, rating: %{score: 10})
|> Ash.create!()
assert [%{score: 10}] =
Post
|> Ash.Query.load(:ratings)
|> Ash.read_one!()
|> Map.get(:ratings)
end
end