Custom Fields
Re-Envisioned
Support MB Relationships Massive bug found (?) with relationships between posts and users!!!!

  • Creator
    Topic
  • #24535
    Resolved JC
    Participant

    This is my use-case:

    A "student" (user) buys a "course" (custom post type) and upon purchase, a relationship is created between the user and the post. This is what grants the user access to the course content.

    All has been working wonderfully. Until today.

    A course was removed from ALL users who had a relationship with that course! This was NOT supposed to happen.

    This happened immediately after I deleted a single user.

    Upon further investigation I found that coincidentally the user who was deleted had the exact same ID as the course that went missing for all other users that had a relationship with it.

    Upon deleting that particular user, it deleted all rows in the mb_relationships table which pointed to that post/course with the same ID.

    To be clear, I deleted a user with the ID of 154 and then any reference in the mb_relationships table to a course with an ID of 154 was removed.

    Here is the method in my plugin code which creates the relationship.

    
    protected function register_relationship_for_user_tutorial_access() {
    
        \MB_Relationships_API::register([
            'id'   => 'the1914_user_to_tutorial',
            'from' => [
                'object_type' => 'user',
                'meta_box'    => [
                    'title' => 'Tutorials',
                ]
            ],
            'to' => [
                'object_type' => 'post',
                'post_type'   => 'tutorial',
                'meta_box'    => [
                    'title' => 'Students',
                ],
                'query_args' => [
                      'post_parent' => 0,   // Show ony parent tutorials
                      'number' => 100       // Maximum to show in the admin area
                ]
            ],
            'reciprocal' => true // Prevent metabox showing in the 'to' (tutorial) post type
        ]);
    
    }
    

    Is this an oversight from the developers of this plugin?

    Or is this expected behaviour based on my code above?

    I have since set 'reciprical' to FALSE in case that had something to do with it. That does not solve this issue.

    Furthermore, when I access the profile of a user to add or remove courses, if the user ID matches a course ID, I get a LOT of dropdown menus appear like this:


    Image

    Here is a screenshot of the mb_relationships table:


    Image

    Thank you for your assistance and for an otherwise great set of plugins!

Viewing 2 replies - 11 through 12 (of 12 total)
  • Author
    Replies
  • #30106
    JC
    Participant

    Apologies for the late reply.

    I have installed the latest MB User Meta plugin (v 1.2.9).

    I have followed my replication instructions here.

    The good news is that when I deleted the user who shared the same ID as the post, all other users who were associated with the post REMAINED associated with the post. (Previously they all lost their relationship with that post!) So this is great, thank you.

    However, before I deleted the user who shared the ID with the post. I noticed this:

    Issue

    What I SHOULD be seeing here is this:

    Issue

    The post "TESTING" shares the same ID as the user.

    So one bug fixed but another remains:

    If the user shares the same ID as the post they are associated with. It doesn't render the user's associations correctly in the user profile

    Thanks for your help 🙂

    #30141
    Long Nguyen
    Moderator

    Hi,

    Thank you for your feedback.

    Please assign the setting reciprocal to true and re-check this issue. Let me know how it goes.
    https://docs.metabox.io/extensions/mb-relationships/#reciprocal-relationships

Viewing 2 replies - 11 through 12 (of 12 total)
  • You must be logged in to reply to this topic.