Creating, Updating, and Deleting MBO Records

Perform create, update, and delete operations on the MBO instances that you have created.

You can call the create, update, and delete methods for MBO instances.

Note: For MBOs with custom create or update operations with parameters, you should use the custom operations, rather than the default create and update operations. See MBOs with Complex Types.
  1. Suppose you have an MBO named Customer. To create an instance within the database, invoke its create method, which causes the object to enter a pending state. Then call the MBO instance's submitPending method.
    SMP101Customer *newcustomer = [[SMP101Customer alloc] init];
    newcustomer.fname = @"John";
    ... //Set the required fields for the customer
    [newcustomer create];
    [newcustomer submitPending];
  2. To update an existing MBO instance, retrieve the object instance through a query, update its attributes, and invoke its update method, which causes the object to enter a pending state. Then call the MBO instance's submitPending method. Finally, synchronize with the generated database:
    SMP101Customer *customer = [SMP101Customer findByPrimaryKey:32838]; //find by the primary key
    customer.city = @"Dublin"; //update any field to a new value
    [customer update];
    [customer submitPending];
  3. To delete an existing MBO instance, retrieve the object instance through a query and invoke its delete method, which causes the object to enter a pending state. Then call the MBO instance's submitPending method. Finally, synchronize with the generated database:
    SMP101Customer *customer = [SMP101Customer findByPrimaryKey:32838];
    [customer delete];
    [customer submitPending];
    For an object tree with MBOs in a composite (cascading) relationship, submitPending submits changes found in the entire hierarchy. If each MBO in the hierarchy has its own CUD operations, the submitted object tree replays in this order:
    • Create and Update: a preorder traversal, for example, parent -> left child -> right child. That is, create the parent before the children.
    • Delete: a postorder traversal, for example, left child ->right child->parent.
    Left and right in this context means from the first child in the children list to the last child. For a tree with multiple operation types, for example, root (update) and two children (one create and one update) and each child has two children, the order of the operation is: root (update), child one(create), children of child one(create), children of child two (delete), child two (delete).
Related reference
Operations APIs