Application ID
77174A3A-8AD8-F997-FF5F-8CE8CB660D00
Expected Behavior
Create an object and then relate this object to another existing one from another table using transactions.
Actual Behavior
When I try to create an object and then relate this object to another existing one from another table using transactions sometimes I get this error:
TransactionOperationError: com.backendless.services.persistence.internal.SqlDatabaseException: Cannot add or update a child row: a foreign key constraint fails (77174A3A-8AD8-F997-FF5F-8CE8CB660D00
.GiftOrders.Users.doctor
, CONSTRAINT 92CC31CF-0CDF-11FE-FF40-F641C9BDF500_ibfk_1
FOREIGN KEY (rel_from
) REFERENCES udt.GiftOrders
(objectId
) ON ) at _class.setResult (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless/lib/unit-of-work/index.js:227:24) at _class._callee$ (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless/lib/unit-of-work/index.js:194:55) at tryCatch (/usr/local/lib/node_modules/backendless-coderunner/node_modules/regenerator-runtime/runtime.js:63:40) at Generator.invoke [as _invoke] (/usr/local/lib/node_modules/backendless-coderunner/node_modules/regenerator-runtime/runtime.js:293:22) at Generator.next (/usr/local/lib/node_modules/backendless-coderunner/node_modules/regenerator-runtime/runtime.js:118:21) at asyncGeneratorStep (/usr/local/lib/node_modules/backendless-coderunner/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24) at _next (/usr/local/lib/node_modules/backendless-coderunner/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9) at processTicksAndRejections (internal/process/task_queues.js:97:5) { operation: OpResult { uow: _class { app: [Backendless], payload: [Object], usedOpIds: [Object] }, operationType: ‘SET_RELATION’, table: ‘GiftOrders’, payload: { parentObject: [OpResult], relationColumn: ‘doctor’, unconditional: [Array] }, opResultId: ‘set_relationGiftOrders1’, result: null, error: [Circular] } }
The steps I follow to do this are:
- const unitOfWork = new Backendless.UnitOfWork();
- unitOfWork.setIsolationLevel(Backendless.UnitOfWork.IsolationLevelEnum.READ_UNCOMMITTED);
- const persistedResult = unitOfWork.create(‘MyTable1’, {code});
- unitOfWork.setRelation(persistedGiftOrdersResult, ‘MyTable2’, [{objectId : correctObjecId}]);
- unitOfWork.execute().then(result => {
return result.isSuccess();
})
I send the correct objectId related but in my log, I notice a different Id.