Let the platform do the work

Relationships

Overview

Relationships are the basis for linking information within the system. This page explains the various aspects of relationships. For information on custom relationships, please refer to the Custom Relationships documentation.

Definitions

Relationships are initially defined in the module's vardefs file under the relationships array. For reference, you can find them using the vardef path ./modules/<module>/vardefs.php.

Database Structure

In Sugar, most relationships are stored using a joining table. This applies to both one-to-many (1:M) relationships as well as many-to-many (M:M) relationships. An example of this is the relationship between Accounts and Opportunities where there are three tables: accountsaccounts_opportunities, and opportunities. You will find that the joining table, accounts_opportunities, will contain the fields needed in order to establish the relationship link.

The fields on the accounts_opportunities table are listed below:

Fields Description
id A unique identifier for the relationship row (not typically used)
opportunity_id The ID for the related opportunity record. This is named uniquely based on the relationship
account_id The ID for the related account record. This is named uniquely based on the relationship
date_modified The date the row was last modified
deleted Whether or not the relationship still exists

Relationship Cache

All relationships in Sugar are compiled into the cache directory ./cache/Relationships/relationships.cache.php. If needed, the relationships cache can be rebuilt by navigating to Admin > Repair > Rebuild Relationships.

Topics

This page needs an overview