Spent quite a bit of time researching this topic and integrating solutions found on various forums. Problem with most of the approaches is that it takes a lot of custom code writing (template files, JS to enable the calendar, vardefs etc. etc. etc.) and the approaches are not upgrade safe OR the solutions do not allow the end user to modify the data (the one I found on the sugarmods forum).
The following solution is 100% upgrade safe, it’s easy to create editview template to allow the end user to modify the data and it’s much more straight forward.
Since we can’t upload anything here at the moment I put all the files + the PDF here.
Here’s the 3 part tutorial:
Intro overview: https://youtu.be/1siUrkKj67k
Create the fields: https://youtu.be/Yr9IvECTIeo
Make editable by end user: https://youtu.be/KYVhQx21ugk
This will definitely save A LOT of time for someone who’s trying to integrate this for the first time.
First of all, thanks once more for your excellent videos. I think this kind of tutorial is much easier to follow than written tutorials. I wish I had found more of these when I was learning.
The approach you use here is interesting, and original. I must say I did get these fields in relationships to work, in upgrade-safe way, and with the ability for the user to change the data, without the need to add a separate module for the relationship fields. I basically did a mix of the Eggers tutorial, and the SugarMods tutorial. Took me ages to get it working but once I nailed it, it has been working well throughout many upgrades.
Mine is a Contacts-to-Contact relationship, for a school where everybody is a Contact (students, parents, teachers) and then the relationships between them have say how they are related. I added an after_save logic hook to make these relationships symmetrical: if I say a kid is the “son” of someone, then that someone becomes the “father” of the kid automatically.
Thank you for the feedback and glad you liked it! I thought if the 2 modules are core modules the adding of the relationship fields would have to be done in metadata folder directly not in custom/metadata. Apart from that I think the rest is upgrade safe you’re right and it’s such a trivial task that you could just add them directly to the database, so definitely your approach is also good.
I like this approach also because when you start adding multiple fields and layout is more complex then the eggsurplus solution becomes very tedious. Alignment of fields, adding each one in vardefs etc, deciding what column type to use, adding custom JS for calendars etc.
But if you have just 1 field, it’s a good approach too.
Oh yeah. I tried these kind of relationships some years ago, and it was not easy to get them right.
Good you made it easier now for people to implement.
@robert_sinclair The link to the files are broken, could you reupload? please