Create a Many-To-One or One-To-One Relationship

You can create a many-to-one or one-to-one relationship from a business object's Overview tab. Here are examples of a many-to-one (or one-to-many) and a one-to-one relationship:

  • A many-to-one relationship between the Employee and Department business objects means a department can have many employees but each employee can only work for one department.
  • A one-to-one relationship between the Employee and EmployeePII objects means that each employee has one set of sensitive personally identifying information and that information belongs to only one employee.

To create a many-to-one or a one-to-one relationship:

  1. Go to your source business object's Overview.
  2. Click + Relationship, then select Many to One / One to One.
  3. In the Create Relationship dialog, select the target business object.

  4. Check the cardinality between the objects. The default cardinality between objects is many-to-one.
    • To create a one-to-many relationship between A and B, you need to create a many-to-one relationship between B and A. Click Reverse Relationship to switch the position of objects in the relationship.
    • To create a one-to-one relationship, change the cardinality from Many to One to One to One.
  5. If needed, change the target object's Accessor Name, which you'll need to issue REST calls.
  6. If you want to access the source object from the target object, select Enable Accessor for the target object.

    By default, the accessor from the source object to the target object is enabled (departmentObject for Employee, in our example). This means that if you were to drag the Employee object onto a page to create a table, you'll be able to fetch the employee's details, including the department they work in. But if you want to access Department from Employee (say, to fetch employees in each department), you must enable the accessor for the target object (employeeCollection for Department, in our example).

  7. Select a Display Field for the target object. The best choice for this option is a string field that's both unique and required. Look for such fields under Unique Required String Fields in the drop-down. If none exist, you might need to select a suitable field; by default, the first field listed under Other Fields is selected.
  8. Now in the source object's Mapping field, specify the new field that will be created as the referenced key (default), or select an existing field. A referenced key is like a foreign key in a database table. It's a field that refers to the key (say, the Id field) of another business object to link the two business objects together.
  9. If needed, change the automatically generated Accessor Name.
  10. Keep Enable Accessor selected for the source object to retain access to the other business object.
  11. Select a Delete Rule to determine what happens when a record that has a relationship to another record is deleted. Your choices are:
    • Restrict (default): You aren't allowed to delete a parent that has children (the default rule for a many-to-one relationship)
    • Cascade: When you delete a parent, the children of that parent are automatically deleted
    • Set To Null: When you delete a parent, the mapping field in the children is set to null.
  12. Click Create.
The new relationship is displayed in the Relationships list on the Overview page, along with the accessor that lets you access the business object at the other end of the relationship. Clicking the accessor name will take you to the Fields tab, where you'll see the accessor listed along with other fields.

For referenced business objects, the relationship between the current business object and the one being referenced is, by default, many-to-one. When you create a reference from, say, an Employee business object to a Department business object, an Employee can belong to only one Department, but a Department normally has many employees. Such a relationship is first shown as a dotted line for the object that represents the "one" side. When you click the line, the details from the "many" business object are loaded and the relationship is shown:
Description of bo-relships.png follows
Description of the illustration bo-relships.png

The referenced business object, Department, also appears in the Endpoints tab for the Employee business object.