Ash FrameworkAF
Ash Framework3y ago
21 replies
xSHYNE

manage_relationship argument not relating primary key to resource

resource
  create :add_to_group do
    argument :group, :uuid do
      allow_nil? false
    end

    change manage_relationship(:group, type: :append_and_remove)
    change relate_actor(:member)
  end
end

relationships do
  belongs_to(:group, Digsync.Accounts.Group, primary_key?: true, allow_nil?: false)
  belongs_to(:member, Digsync.Accounts.User, primary_key?: true, allow_nil?: false)
end


changeset after GroupMembership |> Ash.Changeset.for_create(:add_to_group, %{group: group_id})
#Ash.Changeset<
action_type: :create,
action: :add_to_group,
attributes: %{},
relationships: %{
  group: [
    {"b6937067-651d-4385-8323-20f193f03cd9",
     [
       ignore?: false,
       on_missing: :unrelate,
       on_match: :ignore,
       on_lookup: :relate,
       on_no_match: :error,
       eager_validate_with: false,
       authorize?: true,
       meta: [inputs_was_list?: false, id: :group],
       type: :append_and_remove
     ]}
  ],
  member: [
    {[
       #Digsync.Accounts.User<
         id: "b86d7074-a35a-4df6-8eac-a60327cc254f",
       >
     ],
     [
       ignore?: false,
       on_missing: :unrelate,
       on_match: :ignore,
       on_lookup: :relate,
       on_no_match: :error,
       eager_validate_with: false,
       authorize?: true,
       type: :append_and_remove,
       meta: [inputs_was_list?: false]
     ]}
  ]
},
arguments: %{group: "b6937067-651d-4385-8323-20f193f03cd9"},
errors: [],
>,
valid?: true
>

** (Ash.Error.Invalid) Input Invalid

* record with "b6937067-651d-4385-8323-20f193f03cd9" not found
    (ash 2.11.6) lib/ash/api/api.ex:2124: Ash.Api.unwrap_or_raise!/3


I'm very confused, that id absolute exists and is a Group. When I do a different relationship which is coded almost identically it has a different data structure for the id:

   action_type: :create,
   action: :create_from_flow,
   attributes: %{},
   relationships: %{
     friend_one: [
       {[%{id: "266d68e7-3a8b-401a-a616-1b42c385a811"}],
Was this page helpful?