ash icon indicating copy to clipboard operation
ash copied to clipboard

Modify `manage_relationship` to handle destroy first, or add an option to prioritize it

Open nallwhy opened this issue 1 year ago • 1 comments

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

  1. Click [Add author] button
  2. Click [Remove author] of the first author.
  3. Input "author1" to name of the remain author.
  4. 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

nallwhy avatar Jun 19 '24 02:06 nallwhy

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 👍

zachdaniel avatar Jun 19 '24 12:06 zachdaniel