- This topic has 3 replies, 2 voices, and was last updated 5 days, 1 hour ago by .
-
Topic
-
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:
Here is a screenshot of the mb_relationships table:
Thank you for your assistance and for an otherwise great set of plugins!
- You must be logged in to reply to this topic.