How to set default values to be used with manage_relationship

I’m making good use of the “change manage_relationship” dsl in a resource update action.

My question is: how to augment the :map argument coming into the action with some default values to be used in the create action in the related resource?

Using a change before_action callback can work but feels too heavy.

I’d prefer to have the incoming map argument be lean and then have lean code in the parent resource update it to mix in the default values to as the manage_relationship/4 input to the child resource.

Any pointed will be very happily and gratefully received

Thanks
Martin

you can use Ash.Changeset.set_argument in a change that is before the manage_relationship change, to overwrite the argument to a new value.

1 Like

Thanks Zach.

So with that nugget I was looking at the documentation and am puzzled how to use that in an action. I had assumed that I could use change set_argument… - but clearly cannot as that doesn’t exist on the DSL.

I apologize for asking but what am I missing here? I thought that I was getting a good grasp on using the documentation to control the actions, but don’t (yet) see how to add thet set_argument in the update action.

Thanks again

Martin

you’d do it with a custom change. for example:

change fn changeset, _ ->
  Ash.Changeset.set_argument(changeset, :arg, ....)
end
1 Like

Makes complete sense (now!). Many thanks.

1 Like