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:

SampleAppCustomer *customer = [ SampleAppCustomer find: 32] 
//find by the unique id
customer.city = @"Dublin"; //update any field to a new value
[customer update];
[customer submitPending];
while ([SUP101SUP101DB hasPendingOperations])
[NSThread sleepForTimeInterval:0.2];

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

SampleAppSales_Order* order = [SampleAppSales_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
while ([SUP101SUP101DB hasPendingOperations])
[NSThread sleepForTimeInterval:0.2];

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

SampleAppCustomer *customer = [ SampleAppCustomer find: 32]
SUPObjectList* orderlist = customer.orders;
SampleAppSales_Order* order = [orderlist item:0];
order.sales_rep = @"Ram";
customer.state = @"MA" ;
[customer save];
[customer submitPending];
while ([SUP101SUP101DB hasPendingOperations])