I am building a website for a educational program where there are three roles: Instructor, Student Mentor, and Student Mentee. Using the references module, I'm able to link Mentor profiles to mentee profiles pretty nicely. Only instructors (and admins) are allowed to create references between mentors and mentees, and I'm using the Rules module to automate the process. For instance, if the instructor edits a mentor's profile to reference two mentees, the two mentees' profiles are updated to be referenced to that mentor.
That is easy enough. However, in implementing the reverse situation, updating the mentee's profile which then updates the mentor's profile is a problem because of recursion. I have it currently working with adding a mentor to a mentee's profile, but cannot successfully implement the ability to remove a mentor from a mentee's profile. That's because when a mentor profile is updated all the references are removed (before save) and then added again (after update). What that creates are two situations that look identical to the Rules module (a mismatch between mentee and mentor references would look the same to the Rules conditionally, but can differ contextually- it could mean that the mentee was recently referenced in updating the mentor profile, or it could mean that the mentee profile was updated by an instructor to strip that mentee of a mentor.)
Okay, if that thoroughly confused you, my question could simply be this: Is there a way with rules to determine who triggered the action? Discriminating between a user and a rule? And/Or is there a way to test the new data that are being saved to an entity against the original data? Discriminating between the data that Rules "sees" before saving a profile and the data it "sees" after updating a profile?
Thanks,
three2em
Comments
Why backlinks?
Why do you want to have reference fields on both mentors and mentees? To me it seems like duplicating information.
If the reason is that you want to display the information, then I would set the reference on mentees (or mentors) only, and then use Views to list all relevant mentees when viewing a mentor (or vice versa).
Another approach would be to use the Relation module.
I hope this helps a bit!
//Johan Falk, Sweden
Thanks
Itangalo,
Thanks for your reply. My aim is more for administrative purposes than display. The idea is that the Instructor or Admin users would be able to administer these relations between mentors and mentees, and ideally I would like the instructor or admin users to be able to update these relations from either the mentors' profiles or the mentees'. I have looked into the Relations module, but I'm not really keen on the idea of creating an entity from a relationship.
Thanks again,
-three2em