Support » Plugin: Advanced Custom Fields: Extended » bidirectional relationship inside repeater

  • Hi, i already searched the whole internet and ACF docs, ACFE docs etc. and i am aware that this is a difficult topic.

    but i have to ask!

    is it possible to have a relationship inside a repeater to update another relationship?

    a bit more in detail:
    – CPT “Movie” has a repeater field with a relationship field “Actor”
    – CPT-“Actor” has a (top-level) relationship field “related movies”
    – adding an “Actor” on a “Movie” should update the “related movies for an “Actor”

    what i don’t need:
    i don’t want to manually change the “related movies” on CPT-“Actor” and further this should not update the relationship field on CPT-“Movie”. it’s just one way

    i think i once had it setup the way i want it but on my long development journey it got lost and i need it back 😉

    • This topic was modified 1 month, 3 weeks ago by jkjkjk.
Viewing 1 replies (of 1 total)
  • Plugin Author hwk-fr

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    In your ticket title you said you need to setup a “bidirectional relationship”, then later you said it should be only “one-way”. The approach is quite different in one or the other case.

    Regarding the Bidirectional Setting of ACF Extended it will work in Groups & Clones, but not within Repeater or Flexible Content, as it is flawed by design and those fields make it unsustainable.

    in fact, Repeater/Flexible Content allow to virtually add an unlimited number of relationship fields which are independant one of each other. Which means one Relationship inside a row is not aware of the other relationship in other rows. If you need further explanations as of why it is unsustainable, please read my answer here.

    In your case, I would recommend to use one Relationship field to add Movies, and one relationship to add Actors, but not inside a Repeater.

    If you really need to use it within a repeater, then you could try to implement that “one way” relationship using the acf/update_value or the acf/save_post hook in order to update the distant selected actor.

    Be advised that you would also take care of the case where a Repeater row is deleted by the user, or if an actor is changed/removed inside a row, in order to update the previous distant actor to remove the related movie in its relationship.

    This is where we hit the limit of the system, since an actor could be moved to an another row. You should probably use the acf/save_post hook in that case, since it will let you hook before and after the values are saved using the hook priority (See documentation). So you will able to compare both values to know which actor should be deleted or not. I don’t know how you could take care of the case where an actor is set multiple times in different rows, you could try to validate it using the acf/validate_save_post.

    As the topic is kinda out of the bound of the ACF Extended plugin support, if you need further assistance with ACF custom development questions like this one, I would recommend to head over the ACF Support Forum. There is a large community of developers which will be most likely able to help you there.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.