mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 13:03:14 +12:00
add test to show error with building a reference
This commit is contained in:
parent
c3190fe49c
commit
7f11a9d14b
2 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue