Specifying the id of a nested resource in the map passed to parent resource's create action

When I run the following code, the subtask_id ends up being different from what was specified in the “new_task” map. How do I make it persist the predefine ID?

subtask_id = Ash.UUID.generate()      ## let's say this is '1234-xxx'
new_task = 
    %{
          task_name: "Parent resource",
          subtasks: [
             %{
                   id: subtask_id,
                   subtask_name: "nested resource"
                }]
        }
Task
|> Ash.Changeset.for_create(:create, new_task)
|> Tasks.create!()   ### the actual subtask_id persisted is different from "1234-xxx"

In case it matters, the create action of Task includes the following,

 argument :subtasks, {:array, :map}
 change manage_relationship(:subtasks, type: :create)

and the attributes section of Subtask includes

 attributes do
    uuid_primary_key(:id)

Are you on Ash 2.x or 3.x? If you’re on 2.x, you can add writable?: true to the uuid attribute. If you’re on 3.x, you’d do the same, but also ensure that :id is accepted by the create/update action in question.

1 Like

It works beautifully on Ash 2.x. Thank you!!