Update Operation

The update operation updates a record in the local database on the device. To execute update operations on an MBO, get an instance of the MBO, set the MBO attributes, then call either the save() or update() operation. To propagate the changes to the server, call submitPending.

In the following examples, the Customer and SalesOrder MBOs have a parent-child relationship.

Example 1: Supports update operations to parent entities. The sequence of calls is as follows:

SUP101Customer *customer = [ SUP101Customer find: 32] 
//find by the unique id
customer.city = @"Dublin"; //update any field to a new value
[customer update];
[customer submitPending];
[SUP101SUP101DB synchronize];

Example 2: Supports update operations to child entities. The sequence of calls is:

SUP101Sales_Order* order = [SUP101Sales_Order find: 1220];
order.region = @"SA"; //update any field
[order update]; //call update on the child record
[order refresh]; 
[order.customer submitPending]; //call submitPending on the parent
[SUP101SUP101DB synchronize];

Example 3: Calling save() on a parent also saves any modifications made to its children:

SUP101Customer *customer = [ SUP101Customer find: 32]
SUPObjectList* orderlist = customer.orders;
SUP101Sales_Order* order = [orderlist item:0];
order.sales_rep = @"Ram";
customer.state = @"MA" ;
[customer save];
[customer submitPending];
[SUP101SUP101DB synchronize];