ash
ash copied to clipboard
Modify `manage_relationship` to handle destroy first, or add an option to prioritize it
Is your feature request related to a problem? Please describe.
When trying to delete the existing item and add a new one with manage_relationship, failures can be occur due to identity issues. This happens because delete_unused is after ‘handle_input’ in manage_relationship.
Steps to Reproduce
https://gist.github.com/nallwhy/d0ec48edcfff5a4d34bf5124ef010b63
- Click [Add author] button
- Click [Remove author] of the first author.
- Input "author1" to name of the remain author.
- Click [Save]
Describe the solution you'd like
It would be beneficial to have the option to perform delete_unused before handle_input.
Describe alternatives you've considered
I have no alternatives idea.
Express the feature either with a change to resource syntax, or with a change to the resource interface
For example
changes do
change manage_relationship(:authors, type: :direct_control, delete_unused_first?: true)
end
Additional context x
Try adding use_identities [:post_id_name] to your manage_relationship options. That should inform us that it is actually an update of the relevant matching record. With that said, in an ideal world we would delete the unused ones prior to everything happening without requiring an option, so I'll leave this open. ManagedRelationships still needs to be rewritten to leverage bulk actions internally, so that would be a good time to do it 👍