Skip to content

Adding to a relation

This operation adds child objects to a parent in a relationship. Unlike the Setting a relation operation, which removes any existing child objects and sets the provided children, this operation adds the children to the existing ones.

Specific Children

There are multiple "flavors" of this operation, but in its core, it must reference a parent object and one or more child objects. The parent object must have a valid objectIdvalue. The APIs are grouped below by how the parent object is identified - using objectId, as a map, as an instance of a custom class or as a result of a previous operation in the same transaction:

// Add the objects identified with objectId values in the childrenObjectId array
// to the already existing collection of children of the parent object identified
// with parentObjectId. The parent object must be in the table with the 
// parentTableName name. The relationship column between the parent and child 
// objects is columnName. In other words, for the relationship represented through
// the columnName column, add the child objects to the parent object. Both child
// and parent objects are identified with objectId values.
unitOfWork.addToRelation( tableName: string, 
                          parentObjectId: string, 
                          columnName: string, 
                          childrenObjectId: string[] );

// Same as the above with the only difference is the child objects are instances
// of a custom class. It is important that the class which children objects are 
// instances of, matches the child table name. For example, if the 
// relationship is between tables Person and Address, then the class of child objects
// must be "Address".
unitOfWork.addToRelation( tableName: string, 
                          parentObject: object, 
                          columnName: string, 
                          children: object[] );

// Add the objects represented by the "children" argument to the already existing
// collection of children of the  parent object. The parent object is identified 
// by its objectId with the parentObjectId argument. The parent object must be 
// stored in a table with the parentTableName name. The "children" argument is a
// result of a previous operation in the same transaction. It must represent 
// either a collection of string values (objectIds) or a collection of objects. 
// This is possible with the following previous operations:
//   - Retrieving objects from the database
//   - Saving multiple objects in the database
// It is important that all child objects referenced by the children argument exist
// in the child table that columnName points to.
unitOfWork.addToRelation( tableName: string, 
                          parentObjectId: string, 
                          columnName: string, 
                          children: OpResult );
// Add the objects from the childrenObjectId array to the already existing
// collection of children of parentObject. The array must contain objectId 
// values of the child obbjects. The parent object must be in the table with 
// the parentTableName name. The relationship column between the parent and 
// child objects is columnName. In other words, for the relationship 
// represented through the columnName column, set the child objects to the
// parent object. The parent object must have the "objectId" key with a
// valid value.
unitOfWork.addToRelation( tableName: string, 
                          parentObject: object, 
                          columnName: string, 
                          childrenObjectId: string[] );

// Same as the above with the only difference is the child objects are instannces
// of a custom class. It is important that the class of the children objects 
// matches the child table name. For example, if the relationship is between 
// tables Person and Address, then the class of children objects must be "Address".
unitOfWork.addToRelation( tableName: string, 
                          parentObject: object, 
                          columnName: string, 
                          children: object[] );

// Add the objects represented by the "children" argument to the already
// existing collection of children of the parent object. The parent object must
/// have the "objectid" key. The parent object must be stored in a table with
// the parentTableName name. The "children" argument is a result of a previous 
// operation in the same transaction. It must represent either a collection of
// string values (objectIds) or a collection of objects. This is possible with
// the following previous operations:
//   - Retrieving objects from the database
//   - Saving multiple objects in the database
// It is important that all child objects referenced by the children argument 
// exist in the child table that columnName points to.
unitOfWork.addToRelation( tableName: string, 
                          parentObject: object, 
                          columnName: string,  
                          children: OpResult );
// Add the objects identified with objectId values in the objectIds 
// array to the existing collection of children of parentObject. The 
// relationship column between the parent and child objects is "columnName". 
// The parent object must have the "objectId" key with a valid value. 
// The child objects are identified with their objectId values. Since the 
// parent object is an instance of a develoepor-defined class, it means
// the parent table where the parent object is stored, must match the name
// of the class. For example, if the parentObject class is "Person", it 
// means Backendless wiil:
// 1. Look for the parent object in the Person table using "objectId" key
//    in parentObject.
// 2. Locate a column with the columnName name in the Person table
// 3. Using the column definition, Backendless will identify the child table
// 4. Backendless will retrieve the child objects from the child table using 
//    the provided objectId values.
// 5. Backendless wiill add the child objects and to the relationship of the 
//    parent object.
unitOfWork.addToRelation( parentObject: object, 
                          columnName: string, 
                          objectIds: string[] );

// Same as the first signature above with the only difference is the child 
// objects are not strings. It is important that each child object has the
// "objectId" key with a valid value.
unitOfWork.addToRelation( parentObject: object, 
                          columnName: string, 
                          children: object[] );


// Same as the first signature above with the only difference is the children
// argument is a result of a previous operation in the same transaction. It 
// must represent either a collection of string values (objectIds) or a 
// collection of objects. This is possible with the following previous 
// operations:
//   - Retrieving objects from the database
//   - Saving multiple objects in the database
// It is important that all child objects referenced by the children argument 
// exist in the child table that columnName points to.
unitOfWork.addToRelation( parentObject: object, 
                          columnName: string, 
                          children: OpResult );
// Add the children identified with their objectId values from the 
// childrenObjectId array to the existing collection of the related 
// children of parentObject. The parentObject value is a result of 
// a previous operation in the same transaction. These operations can be:
//   - Saving a single object in the database
//   - Updating a single object in the database
// The relationship is identified through the column with the name in the 
// columnName argument. The column must be declared in the same table where 
// parentObject comes from. It is important that all child objects in the 
// childrenObjectId array exist in the child table that columnName points to.
unitOfWork.addToRelation( parentObject: OpResult, 
                          columnName: string, 
                          childrenObjectId: string[] );

// Same as the first signature above with the only difference is the child 
// objects are not strings. It is important that each child object has the
// "objectId" key with a valid value.
unitOfWork.addToRelation( parentObject: OpResult, 
                          columnName: string, 
                          children: object[] );


// In this operation both the parent and the children objects are results of 
// two separate previous operations in the same transaction. The parent 
// object must be a result of any of the following operations:
//   - Saving a single object in the database
//   - Updating a single object in the database
// The relationship is identified through the column with the name in the 
// columnName argument. The column must be declared in the same table where 
// parentObject comes from. The children argument can be a result of the 
// following operations:
//   - Retrieving objects from the database
//   - Saving multiple objects in the database
// It is important that all child objects referenced by the children argument 
// exist in the child table that columnName points to.
unitOfWork.addToRelation( parentObject: OpResult, 
                          columnName: string, 
                          children: OpResult );

Children with a Query

There are APIs where the child objects can be identified with a query using a where clause. These APIs run a query to get the child objects and then sets them to the parent in the relation. Again the APIs are grouped by how the parent object is identified:

// Add the objects identified by whereClauseForChildren to the 
// existing collection of children of the parent object identified 
// by parentObjectId. The parent object must be in the table 
// with the parentTableName name. The relationship column between 
// the parent and child objects is columnName. The 
// whereClauseForChildren query is executed in the child table 
// that columnName points to.
unitOfWork.addToRelation( parentTableName: string, 
                          parentObjectId: string, 
                          columnName: string, 
                          whereClauseForChildren: string );
// Add the objects identified by whereClauseForChildren to the 
// existing collection of children of the parentObject The 
// parent object must be in the table with the parentTableName 
// name. The relationship column between the parent 
// and child objects is columnName. The whereClauseForChildren
//  query is executed in the child table that the columnName 
// column points to.
unitOfWork.addToRelation( parentTableName: string, 
                          parentObject: object, 
                          columnName: string, 
                          whereClauseForChildren: string );
// Add the objects identified by whereClauseForChildren to 
// the existing collection of children of the parent. The 
// relationship column between the parent and child objects 
// is columnName. Since the parent object is an instance 
// of a developer-defined class, it means the parent table 
// where the parent object is stored must match the name 
// of the class. For example, if the class of parentObject 
// is "Person", it means Backendless wiil:
// 1. Look for the parent object in the Person table.
// 2. Locate a column with the columnName name in the Person 
/     table.
// 3. Using the column definition, Backendless will identify 
//    the child table.
// 4. Backendless will run the whereClauseForChildren query
//    in the child table to identify the child objects.
// 5. Backendless wiil add the child objects to the collection
//    of children of the parent object.
// The class of parentObject must have the "objectId" key 
// with a valid value. The child objects are identified with 
// their objectId values. 
unitOfWork.addToRelation( parentObject: object, 
                          columnName: string, 
                          whereClauseForChildren: string  );
// Add the objects identified by the whereClauseForChildren 
// query to the existing collection of children of the parent 
// object. The parentObject value is a result of a previous 
// operation in the same transaction. These operations can be:
//   - Saving a single object in the database
//   - Updating a single object in the database
// The relationship is identified through the column with the
// name in the columnName argument. The column must be declared
// in the same table where parentObject comes from. For example,
// if the parent object is stored in a table called "Person", 
// Backendless wiil:
// 1. Look for the parent object in the Person table
// 2. Locate a column with the columnName name in the Person table
// 3. Using the column definition, Backendless will identify the 
//    child table
// 4. Backendless will run the whereClauseForChildren query in the
//    child table to identify the child objects
// 5. Backendless wiil add the child objects to the collection 
//    of children and the parent object.
unitOfWork.addToRelation( parentObject: OpResult, 
                          columnName: string, 
                          whereClauseForChildren: string );

// Same as the above except the parentObject is a reference 
// to an object within a result of annother operation in the
// same transaction. For example, a result of another operation
// can be a collection of objects. That collection can be 
// returning from either the "Retrieving objects" or "Saving 
//  multiple objetcs" operations. Using the OpResult API you 
// can obtain a single object which can be used as parent 
// in this operation. When a single object from a collection 
// represented by OpResult is referenced, it is represented 
// by the OpResultValueReference class.
unitOfWork.addToRelation( parentObject: OpResultValueReference, 
                          columnName: string, 
                          whereClauseForChildren: string );

Return Value

The operation returns an OpResult object which represents the result of this operation - number of child objects added to the relation.

Examples

The examples are organized by two levels: first is how the parent object is represented in the client program, then by the type of the child collection.

Parent object is represented as

The child objects are represented as

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const giftIds = [ 
   "EE3BF4B5-DB88-1425-FF89-CC11B7707500",
   "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
   "DFFEDE1D-E423-2472-FF71-26EEC3F23700" 
]

// this is the objectId of the parent object.
const personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700";


// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        giftIds );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
const gifts = [
   {objectId : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"},
   {objectId : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"}
]

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const gifts = [
   new Gift({"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"}),
   new Gift({"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"})
]

// this is the objectId of the parent object.
const personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700";


// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });
The Gift class is shown below:
function Gift(args) {
    args = args || {};
    this.objectId = args.objectId || "";
    this.name = args.name || "";
    this.price = args.price || "";
}

const unitOfWork = new Backendless.UnitOfWork();

// compose a query to fetch the gift objects
const queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause("name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')" );

// add the find operation to the transaction
// notice the result of the operation is saved in a constiable -
// it will be used further in the setRelation operation
const gifts = unitOfWork.find("Gift", queryBuilder);

// this is the objectId of the parent object.
const personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700";

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
   personObjectId,
   relationColumnName,
   gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

The child objects are represented as

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const giftIds = [ 
  "EE3BF4B5-DB88-1425-FF89-CC11B7707500",
  "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
  "DFFEDE1D-E423-2472-FF71-26EEC3F23700" 
]

// this is the objectId of the parent object.
const personObjectId = {"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"}


// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        giftIds );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
const gifts = [
   {"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"},
   {"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"}
]

// this is the objectId of the parent object.
const personObjectId = {"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"}


// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const gifts = [
   new Gift({"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"}),
   new Gift({"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"})
]


// this is the objectId of the parent object.
const personObjectId = {"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"}


// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });
The Gift class is shown below:
function Gift(args) {
    args = args || {};
    this.objectId = args.objectId || "";
    this.name = args.name || "";
    this.price = args.price || "";
}

const unitOfWork = new Backendless.UnitOfWork();

// compose a query to fetch the gift objects
const queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause("name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')" );

// add the find operation to the transaction
// notice the result of the operation is saved in a constiable -
// it will be used further in the setRelation operation
const gifts = unitOfWork.find("Gift", queryBuilder);

// this is the objectId of the parent object.
const personObjectId = {"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"}

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
   personObjectId,
   relationColumnName,
   gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

The child objects are represented as

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const giftIds = [ 
  "EE3BF4B5-DB88-1425-FF89-CC11B7707500",
  "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
  "DFFEDE1D-E423-2472-FF71-26EEC3F23700" 
]

// this is the objectId of the parent object.
const personObjectId = new Person({"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"});

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        giftIds );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
const gifts = [
   {"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"},
   {"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"}
]

// this is the objectId of the parent object.
const personObjectId = new Person({"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"});

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const gifts = [
   new Gift({"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"}),
   new Gift({"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"})
]


// this is the objectId of the parent object.
const personObjectId = new Person({"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"});

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
                        personObjectId,
                        relationColumnName,
                        gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });
The Gift class is shown below:
function Gift(args) {
    args = args || {};
    this.objectId = args.objectId || "";
    this.name = args.name || "";
    this.price = args.price || "";
}

const unitOfWork = new Backendless.UnitOfWork();

// compose a query to fetch the gift objects
const queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause("name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')" );

// add the find operation to the transaction
// notice the result of the operation is saved in a constiable -
// it will be used further in the setRelation operation
const gifts = unitOfWork.find("Gift", queryBuilder);

// this is the objectId of the parent object.
const personObjectId = new Person({"objectId" : "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"});

// the name of the table where the parent object is stored
const parentTableName = "Person";

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation( parentTableName,
   personObjectId,
   relationColumnName,
   gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

The child objects are represented as

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const giftIds = [
   "EE3BF4B5-DB88-1425-FF89-CC11B7707500",
   "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
   "DFFEDE1D-E423-2472-FF71-26EEC3F23700"
]


// compose a query to retrieve the person
// from the database
const queryBuilder = Backendless.DataQueryBuilder.create();
// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.setWhereClause( "name = 'John Doe' and age = 36" );

// add the object retrieval operation to the transaction
const findResult = unitOfWork.find( "Person", queryBuilder );

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the setRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
const parentObjectRef = findResult.resolveTo( 0 );

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation(  parentObjectRef,
                         relationColumnName,
                         giftIds );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
const gifts = [
   {"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"},
   {"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"}
]

// compose a query to retrieve the person
// from the database
const queryBuilder = Backendless.DataQueryBuilder.create();
// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.setWhereClause( "name = 'John Doe' and age = 36" );

// add the object retrieval operation to the transaction
const findResult = unitOfWork.find( "Person", queryBuilder );

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the setRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
const parentObjectRef = findResult.resolveTo( 0 );

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation(  parentObjectRef,
                         relationColumnName,
                         gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

const unitOfWork = new Backendless.UnitOfWork();

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
const gifts = [
   new Gift({"objectId" : "EE3BF4B5-DB88-1425-FF89-CC11B7707500"}),
   new Gift({"objectId" : "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"})
]


// compose a query to retrieve the person
// from the database
const queryBuilder = Backendless.DataQueryBuilder.create();
// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.setWhereClause( "name = 'John Doe' and age = 36" );

// add the object retrieval operation to the transaction
const findResult = unitOfWork.find( "Person", queryBuilder );

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the setRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
const parentObjectRef = findResult.resolveTo( 0 );

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation(  parentObjectRef,
                         relationColumnName,
                         gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });
The Gift class is shown below:
function Gift(args) {
    args = args || {};
    this.objectId = args.objectId || "";
    this.name = args.name || "";
    this.price = args.price || "";
}

const unitOfWork = new Backendless.UnitOfWork();

// compose a query to fetch the gift objects
const queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause("name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')" );

// add the find operation to the transaction
// notice the result of the operation is saved in a constiable -
// it will be used further in the setRelation operation
const gifts = unitOfWork.find("Gift", queryBuilder);
// compose a query to retrieve the person
// from the database
const queryBuilder = Backendless.DataQueryBuilder.create();
// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.setWhereClause( "name = 'John Doe' and age = 36" );

// add the object retrieval operation to the transaction
const findResult = unitOfWork.find( "Person", queryBuilder );

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the setRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
const parentObjectRef = findResult.resolveTo( 0 );

// the name of the relation column
const relationColumnName = "wishlist";

// add the setRelation call to the transaction
unitOfWork.setRelation(  parentObjectRef,
                         relationColumnName,
                         gifts );

// run the transaction
unitOfWork.execute()
   .then(function (unitOfWorkResult) {
       // transaction is complete. Use uowResult to check the result
   })
   .catch( function( error ) {
       // Server reported an error.
   });

The child objects are represented as

let unitOfWork = UnitOfWork()

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
let giftIds = ["EE3BF4B5-DB88-1425-FF89-CC11B7707500",
               "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
               "DFFEDE1D-E423-2472-FF71-26EEC3F23700"]

// this is the objectId of the parent object.
let personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObjectId: personObjectId,
                                 columnName: relationColumnName,
                                 childrenObjectIds: giftIds)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [[String : Any]]()

let iPad = ["objectId": "EE3BF4B5-DB88-1425-FF89-CC11B7707500"]
gifts.append(iPad)

let iPhone = ["objectId": "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"]
gifts.append(iPhone)

// this is the objectId of the parent object.
let personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObjectId: personObjectId,
                                 columnName: relationColumnName,
                                 children: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [Gift]()

let iPad = Gift()
iPad.objectId = "EE3BF4B5-DB88-1425-FF89-CC11B7707500"
gifts.append(iPad)

let iPhone = Gift()
iPhone.objectId = "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"
gifts.append(iPhone)

// this is the objectId of the parent object.
let personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObjectId: personObjectId,
                                 columnName: relationColumnName,
                                 customChildren: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})
The Gift class is shown below:
@objcMembers class Gift: NSObject {
    var objectId: String?
    var name: String?
    var price: Double = 0.0
}

let unitOfWork = UnitOfWork()

// compose a query to fetch the gift objects
let queryBuilder = DataQueryBuilder()
queryBuilder.whereClause = "name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')"

// add the find operation to the transaction
// notice the result of the operation is saved in a variable -
// it will be used further in the addToRelation operation
let gifts = unitOfWork.find(tableName: "Gift", queryBuilder: queryBuilder)

// this is the objectId of the parent object.
let personObjectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObjectId: personObjectId,
                                 columnName: relationColumnName,
                                 childrenResult: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

The child objects are represented as

let unitOfWork = UnitOfWork()

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
let giftIds = ["EE3BF4B5-DB88-1425-FF89-CC11B7707500",
               "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
               "DFFEDE1D-E423-2472-FF71-26EEC3F23700"]

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = ["objectId": "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"]

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist";

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObject: personObject,
                                 columnName: relationColumnName,
                                 childrenObjectIds: giftIds)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [[String : Any]]()

let iPad = ["objectId": "EE3BF4B5-DB88-1425-FF89-CC11B7707500"]
gifts.append(iPad)

let iPhone = ["objectId": "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"]
gifts.append(iPhone)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = ["objectId": "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"]

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObject: personObject,
                                 columnName: relationColumnName,
                                 children: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [Gift]()

let iPad = Gift()
iPad.objectId = "EE3BF4B5-DB88-1425-FF89-CC11B7707500"
gifts.append(iPad)

let iPhone = Gift()
iPhone.objectId = "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"
gifts.append(iPhone)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = ["objectId": "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"]

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObject: personObject,
                                 columnName: relationColumnName,
                                 customChildren: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})
The Gift class is shown below:
@objcMembers class Gift: NSObject {
    var objectId: String?
    var name: String?
    var price: Double = 0.0
}

let unitOfWork = UnitOfWork()

// compose a query to fetch the gift objects
let queryBuilder = DataQueryBuilder()
queryBuilder.whereClause = "name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')"

// add the find operation to the transaction
// notice the result of the operation is saved in a variable -
// it will be used further in the addToRelation operation
let gifts = unitOfWork.find(tableName: "Gift", queryBuilder: queryBuilder)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = ["objectId": "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"]

// the name of the table where the parent object is stored
let parentTableName = "Person"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentTableName: parentTableName,
                                 parentObject: personObject,
                                 columnName: relationColumnName,
                                 childrenResult: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

The child objects are represented as

let unitOfWork = UnitOfWork()

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
let giftIds = ["EE3BF4B5-DB88-1425-FF89-CC11B7707500",
               "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
               "DFFEDE1D-E423-2472-FF71-26EEC3F23700"]

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = Person()
personObject.objectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentObject: personObject,
                                 columnName: relationColumnName,
                                 childrenObjectIds: giftIds)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [[String : Any]]()

let iPad = ["objectId": "EE3BF4B5-DB88-1425-FF89-CC11B7707500"]
gifts.append(iPad)

let iPhone = ["objectId": "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"]
gifts.append(iPhone)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = Person()
personObject.objectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentObject: personObject,
                                 columnName: relationColumnName,
                                 children: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.

var gifts = [Gift]()

let iPad = Gift()
iPad.objectId = "EE3BF4B5-DB88-1425-FF89-CC11B7707500"
gifts.append(iPad)

let iPhone = Gift()
iPhone.objectId = "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"
gifts.append(iPhone)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = Person()
personObject.objectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentObject: personObject,
                                 columnName: relationColumnName,
                                 customChildren: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})
The Gift class is shown below:
@objcMembers class Gift: NSObject {
    var objectId: String?
    var name: String?
    var price: Double = 0.0
}

let unitOfWork = UnitOfWork()

// compose a query to fetch the gift objects
let queryBuilder = DataQueryBuilder()
queryBuilder.whereClause = "name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')"

// add the find operation to the transaction
// notice the result of the operation is saved in a variable -
// it will be used further in the addToRelation operation
let gifts = unitOfWork.find(tableName: "Gift", queryBuilder: queryBuilder)

// this is the parent object. The only property that
// matters for the sake of establishing a relation
// is objectId. In your program you would be
// retrieving the object from the server. The
// technique shown here is for code brevity.
let personObject = Person()
personObject.objectId = "E7AD83E0-1B4E-D250-FF46-61BFAB18D700"

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentObject: personObject,
                                 columnName: relationColumnName,
                                 childrenResult: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

The child objects are represented as

let unitOfWork = UnitOfWork()

// This is an array for child objects.
// They are referenced using objectId values.
// The example hard-codes the array, but in
// your code you'd get the objectId values
// from your data model or using a query
let giftIds = ["EE3BF4B5-DB88-1425-FF89-CC11B7707500",
               "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200",
               "DFFEDE1D-E423-2472-FF71-26EEC3F23700"]

// compose a query to retrieve the person
// from the database
let queryBuilder = DataQueryBuilder()

// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.whereClause = "name = 'John Doe' and age = 36"

// add the object retrieval operation to the transaction
let findResult = unitOfWork.find(tableName: "Person", queryBuilder: queryBuilder)

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the addToRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
let parentObjectRef = findResult.resolveTo(resultIndex: 0)

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentValueReference: parentObjectRef,
                                 columnName: relationColumnName,
                                 childrenObjectIds: giftIds)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [[String : Any]]()

let iPad = ["objectId": "EE3BF4B5-DB88-1425-FF89-CC11B7707500"]
gifts.append(iPad)

let iPhone = ["objectId": "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"]
gifts.append(iPhone)

// compose a query to retrieve the person
// from the database
let queryBuilder = DataQueryBuilder()

// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.whereClause = "name = 'John Doe' and age = 36"

// add the object retrieval operation to the transaction
let findResult = unitOfWork.find(tableName: "Person", queryBuilder: queryBuilder)

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the addToRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
let parentObjectRef = findResult.resolveTo(resultIndex: 0)

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentValueReference: parentObjectRef,
                                 columnName: relationColumnName,
                                 children: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

let unitOfWork = UnitOfWork()

// This is a list of gift objects. These objects
// will be children in the relationship. As you
// can see the objects are constructed manually
// and their objectId's are set, however, in your
// application they would be loaded from the
// server. This is done here to keep the example
// more succinct.
var gifts = [Gift]()

let iPad = Gift()
iPad.objectId = "EE3BF4B5-DB88-1425-FF89-CC11B7707500"
gifts.append(iPad)

let iPhone = Gift()
iPhone.objectId = "0CF23E36-FCC0-4E04-FF3E-8B67E6E27200"
gifts.append(iPhone)

// compose a query to retrieve the person
// from the database
let queryBuilder = DataQueryBuilder()

// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
queryBuilder.whereClause = "name = 'John Doe' and age = 36"

// add the object retrieval operation to the transaction
let findResult = unitOfWork.find(tableName: "Person", queryBuilder: queryBuilder)

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the addToRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
let parentObjectRef = findResult.resolveTo(resultIndex: 0)

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentValueReference: parentObjectRef,
                                 columnName: relationColumnName,
                                 customChildren: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})
The Gift class is shown below:
@objcMembers class Gift: NSObject {
    var objectId: String?
    var name: String?
    var price: Double = 0.0
}

let unitOfWork = UnitOfWork()

// compose a query to fetch the gift objects
let queryBuilder = DataQueryBuilder()
queryBuilder.whereClause = "name in ( 'Apple iPad', 'Apple iPhone', 'Selfie Stick')"

// add the find operation to the transaction
// notice the result of the operation is saved in a variable -
// it will be used further in the addToRelation operation
let gifts = unitOfWork.find(tableName: "Gift", queryBuilder: queryBuilder)

// compose a query to retrieve the person
// from the database
let parentQueryBuilder = DataQueryBuilder()

// this is the query which identifies the person of interest,
// this person object will be used as the parent in the relationship
parentQueryBuilder.whereClause = "name = 'John Doe' and age = 36"

// add the object retrieval operation to the transaction
let findResult = unitOfWork.find(tableName: "Person", queryBuilder: parentQueryBuilder)

// since "findResult" references a collection of objects,
// get the first one from the collection. The reason we need to
// do this is because the addToRelation operation below
// expects only one parent object. We know the first object
// will be the parent, that's why the "resolveTo" index is 0.
let parentObjectRef = findResult.resolveTo(resultIndex: 0)

// the name of the relation column
let relationColumnName = "wishlist"

// add the addToRelation call to the transaction
let _ = unitOfWork.addToRelation(parentValueReference: parentObjectRef,
                                 columnName: relationColumnName,
                                 childrenResult: gifts)

// run the transaction
unitOfWork.execute(responseHandler: { result in
    print("Transaction complete - \(result)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})