mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
29 lines
741 B
Elixir
29 lines
741 B
Elixir
defmodule AshPostgres.PolymorphismTest do
|
|
use AshPostgres.RepoCase, async: false
|
|
alias AshPostgres.Test.{Api, Post, Rating}
|
|
|
|
require Ash.Query
|
|
|
|
test "you can create related data" do
|
|
Post
|
|
|> Ash.Changeset.for_create(:create, rating: %{score: 10})
|
|
|> Api.create!()
|
|
|
|
assert [%{score: 10}] =
|
|
Rating
|
|
|> Ash.Query.set_context(%{data_layer: %{table: "post_ratings"}})
|
|
|> Api.read!()
|
|
end
|
|
|
|
test "you can read related data" do
|
|
Post
|
|
|> Ash.Changeset.for_create(:create, rating: %{score: 10})
|
|
|> Api.create!()
|
|
|
|
assert [%{score: 10}] =
|
|
Post
|
|
|> Ash.Query.load(:ratings)
|
|
|> Api.read_one!()
|
|
|> Map.get(:ratings)
|
|
end
|
|
end
|