add test to show error with building a reference

This commit is contained in:
Barnabas Jovanovics 2024-06-18 10:40:16 +02:00
parent c3190fe49c
commit 7f11a9d14b
2 changed files with 28 additions and 0 deletions

View file

@ -198,6 +198,13 @@ defmodule AshPostgres.AtomicsTest do
|> Ash.update!()
assert post.title == "John"
post =
post
|> Ash.Changeset.for_update(:set_attributes_from_parent, %{})
|> Ash.update!()
assert post.title == "John"
end
test "relationships can be used in atomic update and in an atomic update filter" do

View file

@ -134,6 +134,23 @@ defmodule AshPostgres.Test.Post do
end)
end
update :set_attributes_from_parent do
require_atomic?(false)
change(
atomic_update(
:title,
expr(
if is_nil(parent_post_id) do
author.title
else
parent_post.author.title
end
)
)
)
end
update :update do
primary?(true)
require_atomic?(false)
@ -273,6 +290,10 @@ defmodule AshPostgres.Test.Post do
filter(expr(^actor(:id) == id))
end
belongs_to :parent_post, __MODULE__ do
public?(true)
end
belongs_to(:author, AshPostgres.Test.Author) do
public?(true)
end