Linking Multiple Tables

Hello all,

I am trying to link two tables but have a relationship type for that link identified. For example:

If I have a Teams Module that I have created that is like the accounts module, and I want to link Contacts to the Teams as a many to many relationship, so a contact can be on multiple teams and of course, teams have multiple contacts.

The kicker is I want to identify for that link, what their role is on that team, such as Coach, Player and so on.

[table]
[tr]
[td]Teams Table[/td]
[td]Contacts Table[/td]
[td]Role[/td]
[/tr]
[tr]
[td]Team1[/td]
[td]John Doe[/td]
[td]Coach[/td]
[/tr]
[tr]
[td]Team1[/td]
[td]Jane Doe[/td]
[td]Player[/td]
[/tr]
[tr]
[td]Team2[/td]
[td]John Doe[/td]
[td]Player[/td]
[tr]
[td]Team2[/td]
[td]Jane Doe[/td]
[td]Coach[/td]
[/tr]
[/tr]
[/table]

The goal is to not have to create a new contact/role for each person every time they are added to a team. I only want one John Doe contact in the database and one Jane Doe contact in the database, but when I assigned them to the team I want to specify the role they have.

I was considering creating a Roles Table, that would have the different types of roles (Coach, Adviser, Sponsor, Player…) and then creating relationships to do the linking.

To view it I would foresee having the teams listed, then you click on a team and to see the details, and one of the sub panels would be the Roles, which would list all the roles and show the contact information of the person assigned to that role for that team.

If anyone has any guidance to help me figure this out I greatly appreciate it.

What you’re looking for, I think, is a “relationship field”.

It can’t be done from Studio, I’m afraid…

There is a technical guide here:

http://sugarmods.co.uk/how-to-add-custom-fields-to-a-relationship-table-and-display-them-in-a-subpanel-sugarcrm-suitecrm/

Are you a PHP developer, or do you have one collaborating with you?

1 Like

Thank you pgr, I believe that is exactly what I am looking for!

I have been a php developer in the past, so I am getting to learn the structure of the code for SuiteCRM for some of the customization that we are trying to get to. Just having to try to remove the rust from my skills.

This is not the easiest customization to do in SuiteCRM, let me tell you… I hope you don’t get lost.

If you do, there are additional insights in my post here:

https://suitecrm.com/suitecrm/forum/developer-help/8797-how-create-custom-field-on-accounts-contracts-relatiship-module#31040

Those are good insights as well, I guess the only part I need to figure out (Other than the coding part which is pretty well documented in your first post) is how this changes if I want to use a dropdown list be the control/input method for the new relationship field.

In the walk through you posted they were using a date field. I would assume I need to create the dropdown and then do a linking to that dropdown to the field. So I assume the Metadata file they specify (ustom/metadata/fp_events_contactsMetaData.php) the type would be a varchar and specify the len like 30.
Then I would need to do a custom/metadata/SearchFields.php type file to do the linking between the dropdown and the actual field.

Will be an interesting learning curve :slight_smile:

Thanks again!