Relationships

The Object API supports one-to-one, one-to-many, and many-to-one relationships.

Navigate between MBOs using relationships.

  1. Suppose you have one MBO named Customer and another MBO named SalesOrder. This code illustrates how to navigate from the Customer object to its child SalesOrder objects:
    SUP101Customer *customer = [SUP101Customer findByPrimaryKey:32838];
    SUPObjectList *orders = customer.salesOrders;
  2. To filter the returned child MBO's list data, use the Query class:
    SUPQuery *query = [SUPQuery getInstance];
    [query select:@"c.fname,c.lname,s.order_date,s.region"];
    [query from:@"Customer":@"c"];
    [query join:@"SalesOrder":@"s":@"s.cust_id":@"c.id"];
    query.testCriteria = [SUPAttributeTest match:@"c.lname":@"Devlin"];
    SUPQueryResultSet* resultSet = [SUP101SUP101DB executeQuery:query];
  3. For composite relationship, you can call the parent's SubmitPending method to submit the entire object tree of the parent and its children. Submitting the child MBO also submits the parent and the entire object tree. (If you have only one child instance, it would not make any difference. To be efficient and get one transaction for all child operations, it is recommened to submit the parent MBO once, instead of submitting every child).

    If the primary key for a parent is assigned by the EIS, you can use a multilevel insert cascade operation to create the parent and child objects in a single operation without synchronizing multiple times. The returned primary key for the parent's create operation populates the children prior to their own creation.

    The following example illustrates how to submit the parent MBO which also submits the child's operation:

    SUP101Customer *customer = [SUP101Customer findByPrimaryKey:32838];
    customer.city = @"Dublin";
    SUP101Sales_order* order = [SUP101Sales_order findByPrimaryKey: 1220];
    order.region = @"SA"; //update any field
    [order update]; //call update on the child record
    [order refresh];
    [order.customer submitPending];
Related concepts
Accessing MBO Data
Related reference
Query APIs