One to Many relationship working only with builder

Support MB Relationships One to Many relationship working only with builderResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24444
    Dragan MarianDragan Marian
    Participant

    I have created a One To Many relationship between two post types via builder with ID facilities2states
    One State can have multiple facilities.
    One Facility can have one state.
    using the following settings:
    Facility>Max Items: (empty for unlimited items)
    State>MaxItems: 1 (one to many)

    If I try to edit a Facility, as expected, there is no Add More button for state, which is what I intented to have;
    Because I know of no way to add a relationship to admin columns except code, I generated the php code for the newly created relationship, and this is what I got;

    <?php
    add_action( 'mb_relationships_init', 'facilities2states2code' );
    
    function facilities2states2code() {
        MB_Relationships_API::register( [
            'id'   => 'facilities2states2code',
            'from' => [
                'object_type'   => 'post',
                'post_type'     => 'facility',
                'empty_message' => 'No facility selected',
                'field'         => [
                    'name' => 'Facilities',
                ],
            ],
            'to'   => [
                'object_type'   => 'post',
                'post_type'     => 'state',
                'empty_message' => 'No state selected',
                'field'         => [
                    'name'      => 'State',
                    'max_clone' => '1',
                ],
            ],
        ] );
    }

    For comparing purposes, I changed the relationship id from
    facilities2states to facilities2states2code
    in order to compare the two behaviors;

    The newly created relationship allows adding more States to the Facility post type, which is not the expected behavior:

    comparison

    While this is obviously e code generation bug or a plugin bug, my problem would easily be solved if there would be a way to add a builder created relationship to the admin columns;

    #24451
    Dragan MarianDragan Marian
    Participant

    I have found out what the problem is.
    The PHP code generator added the 'max_clone' value as string, when the accepted value is an integer.
    I have changed
    'max_clone' => '1',
    to
    'max_clone' => 1,
    And the Add More button disappears.

    So, this is a bug on the generator side, because it is not printing 1 value, without single quotes, or on the MB Relationship side, because it is not accepting '1' value as number;

    Still, I would like to know how to add a Builder created Relationship value to the Admin Columns.

    #24454
    Long NguyenLong Nguyen
    Moderator

    Hi,

    When generating code in the Builder, all field's value is wrapped in the single quotes but when parsing data, it will be removed and use the right value type. If you want to use the code on the editor, please remove the single quotes.

    Regarding the admin columns for relationships in the Builder, it has not supported yet. You need to add it by using the code.
    https://docs.metabox.io/extensions/mb-relationships/#admin-column

    #24512
    Dragan MarianDragan Marian
    Participant

    Can we hook on a builder created relationship and add that to the admin columns via code?
    If not, that would be a great feat to have.

    #24517
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I'm going to add this feature request to the to-do list of the development team. It will be included in the next updates as soon as possible.

    Thank you.

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