acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
238 stars 27 forks source link

Bidirectional Fields: Relationship <> Post Object does not remove old connection when overriding #112

Open Ririshi opened 1 year ago

Ririshi commented 1 year ago

Describe the bug I created a Relationship <> Post Object Bidirectional Fields setup between two custom post types called Product and Advisor. Each Advisor can be connected to many Products, but each Product only has one Advisor. Thus, the Product CPT has an ACF field group with a post object field called advisor, and the Advisor CPT has an ACF field group with a relationship field called products. I linked them together using the ACF Extended Bidirectional Fields functionality.

Let's say I have two Advisors, John and Jane, and a single Product called Apple.

When I select Apple in the products field of John, the advisor field for Apple is correctly updated. When I override this by selecting Apple in Jane's products field, the advisor field on Apple correctly updated to Jane. However, the previous Advisor, John, also still has Apple in its products relationship field, even though Apple is now connected to Jane.

To Reproduce

  1. Create two CPTs: Advisor and Product. (I imagine this would work with the default post and page types, too)
  2. Create 2 Advisor posts and 1 Product post.
  3. Create an ACF field group for the Advisor CPT and another for the Product CPT.
  4. Create a relationship field called products on the Advisor CPT's ACF group, selecting Product as the only post type.
  5. Create a post object field called advisor on the Product CPT's ACF group, selecting Advisor as the only post type.
  6. Add a Product to an Advisor's products field.
  7. Add the same Product to a different Advisor's products field.
  8. The Product will still be connected to the first Advisor.

Expected behavior When overriding an existing bidirectional connection between a relationship and a post object field, the old connection should be removed. In my example, I expect John's products field to be updated, removing the Apple reference when Apple is assigned to Jane.

WordPress & ACF WordPress version: 6.1.1 ACF Pro version: 6.0.7 ACF add-ons: Advanced Custom Fields Multilingual: 1.10.4 Advanced Custom Fields: Gravity Forms Add-on: 1.3.5 Advanced Custom Fields: Image Aspect Ratio Crop: 6.0.2 WPGraphQL for Advanced Custom Fields: 0.6.1

Edit: Even if this will not be fixed (if it is classified as intended behaviour), please document that this is how it works. It can be confusing and based on the current documentation for Bidirectional Fields, I would have completely expected it to work the way I described.

acf-extended commented 1 year ago

Hello,

Thanks for the feedback and the detailed report!

I managed to reproduce the scenario you described. To manage such situation it would require an additional bounce check to remove the value if the targeted field is a "single selection".

I've planned to dust off the bidirectional setting codebase, I'll make sure to add this logic to better handle "single selection <> multiple selection" bidirectional scenarios. I'm marking this as feature request, as I'm not 100% sure that everyone would want this (it's the first time someone report it).

I'll try to think about all possible scenarios to make sure it's the most logical for everyone.

Thanks!

Regards.

Ririshi commented 1 year ago

Could you share any information on how much of a priority this request is, and when I can expect an update addressing this? In the meantime, I will instruct clients not to override bidirectional relationships like the one I described from the multiple selection side.