Unit of work doesn't use the mapping to return the right class

Backendless Version (3.x / 5.x, Online / Managed / Pro )

online

Client SDK (REST / Android / Objective-C / Swift / JS )

javascript

Application ID

8C7488E9-5871-4A47-AE5E-2E43E03B85FC

Expected Behavior

based on my understanding from Unit of work and this quote:

The method returns a map between OpResult ID (see the section above) and the result from the corresponding operation using the OperationResult class.

If I mapped a class to the table, the result should return the class and not an object.

Actual Behavior

I’m getting the regular class although the type is correct.

running

const { updatechildren1 } = unitOfWorkResult.getResults();
          const serverChild = updatechildren1.result;

console.log('here', {
            serverChild,
            isOfTypeChildren: serverChild instanceof Children
          })

returns:

{
[debug:backendless]   serverChild: {
[debug:backendless]     firstName: 'עומרי',
[debug:backendless]     created: 1609324049000,
[debug:backendless]     ___class: 'children',
[debug:backendless]     ownerId: null,
[debug:backendless]     isActive: true,
[debug:backendless]     updated: 1609324946000,
[debug:backendless]     objectId: 'F04FC8CF-0E73-37A6-FF87-6392FD47DC00'
[debug:backendless]   },
[debug:backendless]   isOfTypeChildren: false
[debug:backendless] }

Reproducible Test Case

add a class

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

class Children {
  constructor(data, selfOnly = false) {
    _defineProperty(this, "ownerId", null);

    _defineProperty(this, "isActive", null);

    _defineProperty(this, "firstName", null);

    _defineProperty(this, "objectId", null);

    _defineProperty(this, "updated", null);

    _defineProperty(this, "created", null);

    _defineProperty(this, "childClass", null);

    if (!data) {
      return;
    }

    this.ownerId = typeof data.ownerId !== 'undefined' ? data.ownerId : null;
    this.isActive = typeof data.isActive !== 'undefined' ? data.isActive : null;
    this.firstName = typeof data.firstName !== 'undefined' ? data.firstName : null;
    this.objectId = typeof data.objectId !== 'undefined' ? data.objectId : null;
    this.updated = typeof data.updated !== 'undefined' ? data.updated : null;
    this.created = typeof data.created !== 'undefined' ? data.created : null;

    if (selfOnly) {
      return;
    }

    this.childClass = data.childClass ? new Classes(data.childClass) : null;
  }
}

exports.Children = Children;

_defineProperty(Children, "className", 'children');

map the class

  Backendless.Data.mapTableToClass('children', Children);

Thanks!

Hello @Eran_Sakal

Looking into it

1 Like

I’ve checked our JS-SDK and there are no converting objects into its instances.

the quote tells about what the result contains, and this is a map where key is an opResultId and value is an instance of OpResult

Ok Thanks