Understanding Hierarchical Entity Relationships
Hierarchical entity relationships require that one of the records have a field to store a unique identifier that references another record. The record that stores the reference to another record is called the child record. The record referenced by the unique identifier in the child record is called the parent record.
A hierarchical relationship allows each child record to store a reference to one parent record. A parent record can be referenced by an unlimited number of child records. The parent record can display all the child records in an associated view.
Relationships are defined between entities. The entity that will represent the child records is called the related entity. A relationship attribute, also known as a lookup attribute, is created on the related entity to allow records to store a reference to a parent record. The entity that represents the parent records is called the primary entity in the relationship.
- A 1:N Relationship is created or viewed from the primary entity. Any one record from the primary entity can be referenced by many records from the related entity.
A N:1 Relationship is created or viewed from the related entity. Many records from the related entity can reference any one record from the primary entity.
A hierarchical relationship introduces the opportunity to define rules for data integrity. For example, an opportunity record has no meaning if it isn't associated with a customer record. Microsoft Dynamics CRM Online requires that an opportunity record be related to a customer record. However, a task activity can be meaningful whether it is associated to another record or not. Relating a task activity to another record is optional.
When you create a relationship, you must choose whether to enforce rules for data integrity. If you make the relationship field on the related entity required by setting a requirement level of Business Required, you can guarantee that each of the related entity records created through the Microsoft Dynamics CRM Online application will be related to a record of the parent entity.
Once you create a hierarchical relationship, you can control how the relationship behaves to support data integrity and business rules for your organization. The relationship can control how actions performed on a parent record cascades down to a child record.
You can configure the relationship behavior for the following actions performed on the primary entity record:
Choose from three predefined and commonly used types of behavior, or choose to configure the cascading action performed on the record of the primary entity.
The three predefined types of behavior are:
- Parental. All actions cascade down to the child records. Deleting a parent record also deletes all child records. Reassigning a parent record to a user also reassigns all the child records to the same user.
- Referential. No actions cascade down to the child records. Deleting a parent record also deletes any linking data in any child record.
- Referential, Restrict Delete. No actions cascade down to the child records, except that deletion is not allowed if there are any child records.
Also choose to define specific cascading behavior for each of the actions. For most actions, your choices are:
- Cascade All. This is a parental type of behavior. All actions cascade down to all child records, including inactive records.
- Cascade Active. All actions only cascade down to all active child records.
- Cascade User-Owned. Actions only cascade down to child records assigned to the same user as the owner of the parent record.
- Cascade None. This a referential type of behavior. No actions cascade down to child records.
Data integrity must be preserved when data in records changes or when the status of records change. Deleting a parent record breaks the data integrity of any child record if the relationship is required. There are three ways to address this:
- Use Referential, Restrict Delete behavior to prevent the deletion of any record with a child record.
- Use Parental behavior to delete any child record when deleting a parent record.
- Set the Delete action to Cascade All or Referential, Restrict Delete.
If the relationship is not required, it is sufficient to remove the data that establishes the link to the deleted parent record.
In addition to data integrity, your business can apply relationship behavior when data in records change or when the status of records change. The relationship behavior can cascade this action so it does not need to be done manually.
Limitations for Hierarchical Relationships
- Each entity can have only one parental relationship. Most Microsoft Dynamics CRM Online system entities already have a parental relationship and this relationship cannot be changed.
- Entities can have referential relationships with any entity, including business entities. You can create multiple relationships between two entities. Entities can have referential relationships with themselves, allowing linked records of the same type. However, a record cannot be linked to itself.
- In Microsoft Dynamics CRM Online, the customer entities are Accounts or Contacts. These two entities together represent a composite Customer entity. Some Microsoft Dynamics CRM Online business entities, such as Opportunity and Case must be related to a Customer. However, you cannot create this type of relationship with custom entities.
Users can create new child records in an associated view. When this happens, data from the parent record is copied into the form for the new child record. By default, a reference to the parent record is always copied to the relationship lookup field in the child record. You can choose whether data from other fields should be copied at the same time. More information: Mapping Entity Attributes