From and To fields reversed...?

Support MB Relationships From and To fields reversed...?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #49202
    A.A.
    Participant

    When creating a relationship using the UI, both From and To sides have three tabs: General, Meta Box, and Field. The "Field" part appears reversed, so whatever I add in the From > Field section is appearing on the To > Field section in the post edit pages..

    For example, here is the generated code of the relationship I was trying to set up between two post types: Course and Lesson. My plan was to let a Course contain many lessons, but have it so lessons can only belong to one course:

    <?php
    add_action( 'mb_relationships_init', 'your_prefix_register_relationships' );
    
    function your_prefix_register_relationships() {
        MB_Relationships_API::register( [
            'from'        => [
                'post_type' => 'course',
                'meta_box'  => [
                    'title'   => 'Lessons in this Course',
                    'context' => 'normal',
                ],
                'field'     => [
                    'max_clone'  => 1,
                    'add_new'    => false,
                    'add_button' => 'From Add More Text',
                    'name'       => 'From Label',
                ],
            ],
            'to'          => [
                'post_type'    => 'lesson',
                'admin_filter' => true,
                'admin_column' => 'after title',
                'meta_box'     => [
                    'title' => 'Course',
                ],
                'field'        => [
                    'add_button' => 'To Add More Text',
                    'add_new'    => false,
                    'name'       => 'To Label',
                ],
            ],
            'id'          => 'course-to-lesson',
            'delete_data' => false,
        ] );
    }

    NOTE: I temporarily used 'From Add More Text', 'From Label', 'To Add More Text', and 'To Label' to better help describe my issue without having to upload screenshots.

    While the above code is ordered properly, when I go to the Course edit page I see the expected meta box title, 'Lessons in this Course', but the dropdown inside of it has the 'To Label' and the 'To Add More Text'.

    And on the lesson page, the meta box is titled 'Course', as expected, but it has the 'From Label'.

    In other words:
    - The from meta box appears when editing the "from" post type (course). [expected behavior]
    - The field inside it shows related "to" items (lessons). [expected behavior]
    - But the field configuration (labels, clone settings, add-new text) is applied in reverse — the "to" field settings are used on the "from" meta box and vice versa. [NOT the expected behavior]

    Is it meant to be this way?

    I was expecting:
    - The "from > field" settings would appear on the "from" object's edit screen.
    - The "to > field" settings would appear on the "to" object's edit screen.

    It is causing me a lot of confusion. Is this a bug or am I using MB Relationship incorrectly?

    #49219
    PeterPeter
    Moderator

    Hello,

    Thanks for reaching out.

    Yes, that is expected behavior. The field setting will be applied to the reversed object type from <-> to because you are actually using the field of the reversed object type.
    It might be confusing at first time but everything works as it is.

    Let me know if you have any issues when using MB Relationships extension.

    #49265
    A.A.
    Participant

    Thank you, I understand it now. But this was quite confusing to work with at first, and for a long time I thought it was a bug rather than the intended behavior.

    It might help to make this clearer in the UI to avoid confusion for beginners using MB Relationships. Maybe add a short note or tooltip in the “Field” tab mentioning that these settings apply to the opposite post/object type, not the one currently being edited.

    Alternatively, labeling it “Field settings for related items” could make it more intuitive. A quick clarification like this could save users from thinking it’s a bug.

    Also, before posting my initial question, I had checked the documentation but couldn’t find anything clear about this behavior. If the explanation is already there but easy to miss, perhaps consider updating or highlighting it to make it easier to find.

    Thank you again for your time and assistance.

    #49275
    PeterPeter
    Moderator

    Hello,

    I think it is noted in the documentation https://docs.metabox.io/extensions/mb-relationships/#using-code

    The field settings apply from object from to object to. That means the custom field (relationship) shows on the object from get object type, post type, and field settings from object to.

    However, I will inform the development team to add a note about this in the UI to make it clearer.

    Thanks.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.