Understanding Relationship Creation Options


Overview

In Sugar, relationships can be created in either Module Builder (custom module) or Studio (custom and stock module). When a relationship is created via Admin > Studio, relate fields and subpanels are automatically created to represent a two-way relationship between the modules. When a related module record is selected in the relate field or subpanel, a relationship is established between the primary module record and the related module record. This article will go over the different types of relationships and how to create new relationships in Sugar.

Relationship Types

We will go over the different relationship types below.

  • One-to-One : This type of relationship is the most restrictive and will result in a relate field in both modules. You can create the relationship in either the primary or related module. For example, if the account and contact module has a one-to-one relationship, then only one account record can be associated to one contact record and vice versa.
  • One-to-Many : This type of relationship will display a relate field in the related module and the primary module will show a subpanel with the option to choose multiple records. For example, if the Accounts and Contacts module has a one-to-many relationship, the account record will show a subpanel for contacts. This will allow multiple contacts to be associated to the account record. The contact record will show the relate field for accounts where you can relate one account to the record.
  • Many-to-Many : This type of relationship will display a subpanel in both the primary and related module. For example, if the account and contact module has a many-to-many relationship, then multiple accounts can be related to multiple contacts and vice versa.
  • Many-to-One (Module Builder) : This type of relationship will display a relate field in the primary module and the related module will show a subpanel with the option to choose multiple records. For example, if the Accounts and Contacts module has a many-to-one relationship, the contact record will show a subpanel for accounts. This will allow multiple accounts to be associated to the contact record. The account record will show the relate field for contacts where you can relate one contact to the record.

You can also create a circular relationship, which is a module related to itself. This creates a parent/child relationship within the same module and it can be created using any of the above relationship types.

Subpanel Types

When creating relationships that involve subpanels (one-to-many, many-to-many), you have the option to choose the subpanel type you want displayed in the related module. The different subpanel types can display different sets of fields depending on the primary module that it is related to. So the Contacts subpanel displayed in the Accounts module will contain different fields than the Contacts subpanel displayed in the Cases module. For example, if we create a one-to-many relationship between “Accounts” and “Contacts”, the “Subpanel from Contacts” will display the list of subpanel types available for the Contacts module. Select the Default type to get the most commonly used fields in the subpanel, select “ForAccounts” to get the fields from the Contacts subpanel in the Accounts module etc.

Image11-New.png

Creating and Managing Relationship in Module Builder vs Studio

Please note the key differences in creating and managing relationships in Module Builder vs Studio.

Relationship in Module BuilderRelationship in Studio
You can only create relationships between un-deployed modules.You can only create relationships between deployed modules.
You have the ability to edit relationships after the module is deployed, but will need to re-deploy the module package.You cannot edit a relationship in Studio once it has been created, but you can delete relationships.

Creating Relationships

We will go over the steps of how to create a relationship in Studio and Module Builder below.

Studio

We will go over how to create a one-to-many relationship between the Accounts and Notes module as an example.

  1. Navigate to Admin > Studio > Accounts > Relationships and click “Add Relationship”.
    Image1-New.png
  2. Select the relationship type as “One-to-Many” and choose “Notes” as the related module.
    Image2-New.png
  3. Once the custom relationship is saved, it will appear in the list of relationships.
    Image3-New.png
  4. Navigate to Admin > Studio > Notes > Layouts > EditView. Notice that the relate field for the Accounts module will automatically be added to the layout due to the relationship.
    Image4-New.png
  5. Now hover over the Notes module and select “Create Note or Attachment”.
  6. Select the account record to relate to the note. For our example, we will select “Smallville Resources Inc”.
    Image5-New.png
  7. Once the note record is saved, the related account will be displayed in the note record’s detailview.
    Image6-New.png
  8. In addtion, the note record will be displayed in the Notes subpanel of the related account record.
    Image7-New.png

Module Builder

We will go over how to create a many-to-many relationship between the Companies custom module and Tasks module in module builder as an example.

  1. Navigate to Admin > Module Builder and select the custom module. For our example, we will select the Companies custom module.
  2. Select “Relationships” then click “Add Relationship”.
    Image8-New1.png
  3. Select the relationship type as “Many-to-Many” then choose “Tasks” as the related module.
    Image9-New.png
  4. Save the relationship.
    Image10-New.png
  5. Once the custom module is deployed, the Companies module will display a subpanel for tasks and the Tasks module will display a subpanel for Companies.

Managing Relationships

Module Builder

Relationships created in Module Builder can be edited and deleted as follows:

  1. Navigate to Admin > Module Builder > {Custom Module Name} > Relationships and select the relationship name.
  2. Edit the relationship as necessary and click “Save”. For our example, we will change “a1234_companies_tasks” from a many-to-many relationship to one-to-many.
    Image12-New1.png
  3. To delete the relationship, click the delete button.

Studio

Relationships cannot be edited in Studio, but you can delete custom relationships as follows:

  1. Navigate to Admin > Studio > {Module Name} > Relationships and select the relationship name. For our example, we will delete “accounts_calls_1”.
  2. Click “Delete” to remove the relationship from the module.
    Image13-New.png

Quick Tips

  • Before you create the relationship, check to see if the relationship already exists out-of-the-box and review its type.
  • Consider the scalability of your relationship. If most of your existing relationships are one-to-many, then you need a many-to-many relationship. Please note that relationships cannot be changed from one type to another, so consider a more liberal option when relating two modules.
  • When creating relationships in Module Builder, make sure to reference modules that will be deployed simultaneously. This will prevent orphaned relationships from being created.

    BrandonW.png