Relationships
The connections between entities in a data model are called relationships. Relationships reflect business rules. Relationships between entities can be one-to-one, one-to-many, or many-to-many.
For more information about data relationships, see Data relationship fundamentals.
One-to-many relationships within the same data object
The relationship of the Products entity to individual products is one-to-many within the same data object. The following figure shows the Product Information entity.
This is a parent-child relationship where a parent object, .ParentProduct, can have many children objects. The connecting line with crow's foot notation shows the one-to-many relationship and indicates that the child product, .AssociatedChildProducts, is selected from a list of products stored on the Product Information entity.
The header of the entity shows its logical name, Product Information, and the class name, Entity-Product. The Common-LDM-Entity class defines all entities, so the full class name for the entity is Common-LDM-Entity-Product. The class key, ProductID, is the primary key and is an identifier type.
In App Studio, you can see the configuration of this one-to-many relationship. In the Product case type, the Data model tab contains all data fields, as shown in the following figure:
The Product field is a data reference field that holds the details of a product record.
You can view the sample data in the Common application to view a list of products and the parent product name (Security) and ID (PRD-001) as shown in the following figure:
One-to-many across different data objects
The relationship of the Service Accounts entity to the Transactions entity is one-to-many. Each service account can have many transactions, while a transaction can have one service account. The following figure shows the Service Accounts and related Transactions entities:
The connecting line with crow's foot notation shows the one-to-many relationship and indicates that the reference for the Transaction field in Service Accounts is selected from a list of transactions stored on the Transactions entity.
The header of the Service Accounts entity shows its logical name, Service Accounts, and the class name, Entity-ServiceAccount. The Common-LDM-Entity class defines all entities, so the full class name for the Service Accounts entity is Common-LDM-Entity-ServiceAccount. The class key, ServiceAccountID, is the primary key and is an identifier type.
The header of the Transactions entity shows its logical name, Transactions, and the class name, Entity-Transactions. The full class name for the Transactions entity is Common-LDM-Entity-Transactions. The class key, TransactionID, is the primary key and is an identifier type.
For a one-to-many relationship. a property is used to represent the relationship. In the Service Account entity class, a Page List property holds the list of transactions that are associated with the service account. A query field references a data page that retrieves data from a specified data source and caches that data in memory. The Transaction entity class contains the ServiceAccount.ServiceAccountID property to hold the relationship between the service account and the transaction. The data reference field type can produce a list of all the transactions that are recorded for a given Service Account.
In App Studio, you can see the configuration of this one-to-many relationship. In the Service Account case type, the Data model tab contains all data fields, as shown in the following figure:
The Transactions to service accounts list field uses a query to retrieve transactions related to a service account. For example, a telecom provider offers a PremiumPlay mobile and internet service. The Service Account represents the Quad Play Plus service, and a transaction represents the customer's monthly bill. Service Account records are in one database, and Transaction records are in another.
You click the Gear icon to view the configuration of the field. The Transactions to service accounts list field, shown in the following figure, retrieves a list of transactions associated with a service account.
The Transaction field is a data reference field that holds data of a single transaction record. For each transaction, the associated service account details are stored in the ServiceAccount data reference field in a transaction entity record.
You can view the sample data in the Common application to view the Quad Play Plus service account and the transaction relationships on the Related transactions tab, as shown in the following figure:
Many-to-many across different data objects
The relationship between Accounts and Contacts is many-to-many. Each account can have many contacts, and each contact can have an association with many accounts.
The following figure shows the Accounts and Contacts entities. The connecting line with crow's foot notation for the contact and the account fields shows the many-to-many relationship.
An entity can use a data reference field to connect to another entity. For example, the Accounts entity uses the .Contact () field, a data reference, to connect to the Contacts entity.
The Contacts entity also uses a data reference field to connect to the Accounts entity because a contact can have multiple accounts.
Objects with a light blue header represent a relationship between two top-level entities. These objects are created under the Common-LDM-Relation class.
For example, for the many-to-many relationships between an account and a contact, an instance of the Common-LDM-Relation-AccountToContact relationship class is created. The many-to-many relationship classes inherit from Link-Association-M2M. This design involves a flow that includes first a Search and select form and captures input values for the many-to-many records in a second form. You use the API service layer to directly maintain many-to-many records through API calls.
In App Studio, you can see the configuration of this many-to-many relationship, as shown in the following figure. In the Accounts case type, the Data model tab shows all data fields.
The Account to contact relationship field holds the relationship between an account and contact, for example Primary or Owner.
The data model of the Contact case shows all the fields in the Contacts entity, as shown in the following figure
The Account to contact relationship field holds the relationship between the two entities, for example Primary, Owner.
This Topic is available in the following Module:
Want to help us improve this content?