Update Operation

The update operation updates a record in the local database on the device. 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:

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

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

SampleApp_Sales_order* order = [SampleApp_Sales_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 ([SampleApp_SampleAppDB hasPendingOperations])
		[NSThread sleepForTimeInterval:0.2];

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

SampleApp_Customer *customer = [ SampleApp_Customer find: 32]
SUPObjectList* orderlist = customer.orders;
SampleApp_sales_order* order = [orderlist item:0];
order.sales_rep  = @"Ram";
customer.state = @"MA" ;
[customer save];
[customer submitPending];
while ([SampleApp_SampleAppDB hasPendingOperations])
		[NSThread sleepForTimeInterval:0.5];