ash_sqlite/test/polymorphism_test.exs

30 lines
730 B
Elixir
Raw Normal View History

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