addRelation method

  1. @override
Future<int?> addRelation(
  1. String parentObjectId,
  2. String relationColumnName, {
  3. List<String>? childrenObjectIds,
  4. String? whereClause,
})
override

The API request has 2 options:

  1. Must explicitly specify child objects to add to the relation by referring to their identifiers.
  2. Child objects are referenced implicitly through the whereClause clause, which defines the condition for selecting the object.

At least 1 optional parameter must be defined. If 2 optional parameters are defined, 1 option is preferred. The API returns the number of objects the operation adds to the relations.

Implementation

@override
Future<int?> addRelation(String parentObjectId, String relationColumnName,
    {List<String>? childrenObjectIds, String? whereClause}) async {
  String methodName = '/data/$tableName/$parentObjectId/$relationColumnName';
  List<String>? parameters;

  if (childrenObjectIds?.isNotEmpty ?? false) {
    parameters = childrenObjectIds;
  } else if (whereClause?.isNotEmpty ?? false) {
    methodName += '?where=$whereClause';
  }

  return await Invoker.put(methodName, parameters);
}