From 7f11a9d14ba850fd3d0516853fbc6da3a35646cb Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 18 Jun 2024 10:40:16 +0200 Subject: [PATCH] add test to show error with building a reference --- test/atomics_test.exs | 7 +++++++ test/support/resources/post.ex | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/atomics_test.exs b/test/atomics_test.exs index 5a83521..71dedea 100644 --- a/test/atomics_test.exs +++ b/test/atomics_test.exs @@ -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 diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 7f8781e..1516813 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -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