One-to-many relationship on "bay_mb_relationships"

Support MB Relationships One-to-many relationship on "bay_mb_relationships"Resolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18052
    Berg InformatikBerg Informatik
    Participant

    I try to realize a database structure like this.

    https://i.stack.imgur.com/MeCoj.png

    I have 3 post types:
    * Workout
    * Exercise
    * Set

    Thanks to the many-to-many plugin i can connect the Workout and Exercise with ease. But how can i connect the Set's with one-to-many relation to the "bay_mb_relationships" junction table.

    #18072
    Anh TranAnh Tran
    Keymaster

    Hi,

    If you want to force only one connection from one side of a relationship, please set 'max_clone' => 1 to the field on that side, like this:

    add_action( 'mb_relationships_init', function () {
        MB_Relationships_API::register(
            array(
                'id'   => 'workout_to_workout_exercises',
                'from' => array(
                    'object_type' => 'post',
                    'post_type' => 'workout',
                    'field' => array(
                        'max_clone' => 1, // Limit to 1 connection only.
                    ),
                ),
                'to'   => array(
                    'object_type' => 'post',
                    'post_type' => 'workout_exercises',
                ),
            )
        );
    } );
    #18074
    Berg InformatikBerg Informatik
    Participant

    Thanks for the tip. I just got to know the plugin. This plugin is very helpful for creating web applications with WordPress. A small minus is the missing attribute "Required" for some file types like "Map", "Autocomplete", "Color Picker" and "Advanced Image". Anyway, i think i will love the plugin more and more the deeper i dive into programming.

    #18076
    Anh TranAnh Tran
    Keymaster

    Thank you for your kind words and your feedback. We keep improving the plugin and will try our best to make it more useful for you!

    #19200
    Robert WilsonRobert Wilson
    Participant

    Using the example above, I'm wondering how one would go about ensuring that a workout_exercise is only created if a workout has been selected (assigned to it). Essentially, don't allow an exercise to be created without selecting a workout that it is related to. I hope that makes sense.

    Thanks you for creating such a fantastic set of plugins. I would love to see more examples using "Twig".

    #19213
    Long NguyenLong Nguyen
    Moderator

    Hi Robert,

    The extension only helps you to create the relation between the posts, but thanks for the idea, I will discuss with the developer team to support the property 'required' => 1 to check this box not empty like the required fields.

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