From 5c3ea08838cfbcdeb2e5aafbfd45f7eddd49828b Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 27 Apr 2021 14:18:48 -0400 Subject: [PATCH] fix: support embeds in relationships --- lib/ash_phoenix.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ash_phoenix.ex b/lib/ash_phoenix.ex index 83a2226..05bcaf7 100644 --- a/lib/ash_phoenix.ex +++ b/lib/ash_phoenix.ex @@ -593,10 +593,13 @@ defmodule AshPhoenix do """ def add_embed(query, path, outer_form_name, add \\ %{}) - def add_embed(%Ash.Changeset{} = changeset, path, outer_form_name, add) do - [^outer_form_name, key | path] = decode_path(path) + def add_embed(%Ash.Changeset{} = changeset, original_path, outer_form_name, add) do + [^outer_form_name, key | path] = decode_path(original_path) cond do + match?({x, y} when not is_nil(x) and not is_nil(y), argument_and_manages(changeset, key)) -> + add_related(changeset, original_path, outer_form_name, add: add) + attr = Ash.Resource.Info.attribute(changeset.resource, key) -> current_value = Ash.Changeset.get_attribute(changeset, attr.name)