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:
    Customer cust = Customer.findById(101);
    com.sybase.collections.ObjectList orders = customer.getSalesOrders();
  2. To filter the returned child MBO's list data, use the Query class:
    Query query = new Query();
    AttributeTest at = new AttributeTest("sales_rep", new Integer(129), AttributeTest.EQUAL);
    query.where(at);
    orders = cust.getSalesOrdersFilterBy(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:

    Customer cust = Customer.findById(101);
    Sales_order order = new Sales_order();
    order.setId(1001);
    order.setCustomer(cust);
    order.setOrder_date(new Date());
    order.setFin_code_id("r1");
    order.setRegion("Eastern");
    order.setSales_rep(101);
    order.save(); // or order.create();
    cust.save();
    cust.submitPending();
Related concepts
Accessing MBO Data
Related reference
Query APIs