ash icon indicating copy to clipboard operation
ash copied to clipboard

Many to many and on match destroy in `manage_relationship`

Open vonagam opened this issue 2 years ago • 4 comments

I think on_match: :destroy in manage_relationship is incorrect for many_to_many.

Right now it destroys a join resource. Instead it should destroy both a join and a destination like other types of relationships do.

If one wants to destroy only a join resource then they should use :unrelate.

Destroy is implemented correctly for on_missing where :destroy destroys both and :unrelate only join one. (Though there is a mistake in documentation that states that it is possible to pass [:join, :keys] with a long form.) That's the only other case with support for :destroy so it is strange that they are inconsistent.

vonagam avatar Jan 30 '24 22:01 vonagam

Yeah, I think you're correct. It does potentially make sense to be able to pass join keys to a destroy action on a join resource though, since destroy actions can technically take arguments.

zachdaniel avatar Jan 30 '24 23:01 zachdaniel

But not for on_missing since there is no input for those.

vonagam avatar Jan 30 '24 23:01 vonagam

Hi, I’m new to contributing to Ash and noticed this is labeled good first issue, but I also see #2638 is already open. Is there any smaller follow-up, test case, or documentation update related to this that would be useful for a first contribution?

jaredsrice avatar Jun 29 '26 20:06 jaredsrice

👋 thank you for reminding me of that PR. I don't believe there is any needed followup but I very much appreciate you bringing it back to my attention!

zachdaniel avatar Jun 29 '26 23:06 zachdaniel