2023-09-23 14:52:22 +12:00
|
|
|
defmodule AshSqlite.PolymorphismTest do
|
|
|
|
use AshSqlite.RepoCase, async: false
|
2024-04-02 05:18:42 +13:00
|
|
|
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})
|
2024-04-02 05:18:42 +13:00
|
|
|
|> Ash.create!()
|
2023-09-23 14:52:22 +12:00
|
|
|
|
|
|
|
assert [%{score: 10}] =
|
|
|
|
Rating
|
|
|
|
|> Ash.Query.set_context(%{data_layer: %{table: "post_ratings"}})
|
2024-04-02 05:18:42 +13:00
|
|
|
|> 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})
|
2024-04-02 05:18:42 +13:00
|
|
|
|> Ash.create!()
|
2023-09-23 14:52:22 +12:00
|
|
|
|
|
|
|
assert [%{score: 10}] =
|
|
|
|
Post
|
|
|
|
|> Ash.Query.load(:ratings)
|
2024-04-02 05:18:42 +13:00
|
|
|
|> Ash.read_one!()
|
2023-09-23 14:52:22 +12:00
|
|
|
|> Map.get(:ratings)
|
|
|
|
end
|
|
|
|
end
|