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.
Activities and Account Relationships
Calls, Meetings, Tasks, and Notes have a dedicated Account relationship backed by account_id. Its user-facing label is Account. Account relationships must use this field rather than treating parent_type = Accounts and parent_id as the current account link. Related To remains available for other supported parent modules.
The creation context can pre-populate Account. From a Contact, Sugar uses the contact’s account; from a supported parent record, it uses that record’s direct account relationship. A manually chosen account is preserved. Subsequent changes to the Person or Related To fields do not automatically keep account synchronized. API clients should supply the intended account relationship explicitly rather than relying on a browser creation context.
When lead conversion is configured to move activities, moved Calls, Meetings, Tasks, and Notes receive the converted contact’s account relationship where available. A contact with no account does not prevent the activities from moving.
The upgrade migration transfers direct account parent references into account_id and clears the old account parent fields. It also derives account links through supported parent relationships when account_id is empty. Review custom relationship mappings and SQL that depend on the previous parent fields.
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: accounts, accounts_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.