Set relation : error code 25016

Hello,

In an “Add operations to transaction” block I do an upsert operation for each of my two entities and then I do a set relation using the upsert operations reference but I get the following error:

{“success”:false,“error”:{“operation”:{“operationType”:“SET_RELATION”,“table”:“Entity1”,“opResultId”:“relation1”,“payload”:{“conditional”:null,“unconditional”:[{"___ref":true,“opResultId”:“upsert2”,“propName”:“objectId”}],“parentObject”:{"___ref":true,“opResultId”:“upsert1”},“relationColumn”:“relationColumn1”}},“code”:25016,“message”:“Unable to perform ‘SET_RELATION’ operation due to argument incompatibility. The operation references a result from another ‘UPSERT’ operation. The specified result cannot be obtained from this operation (objectId).”},“results”:null}

Could you help me to find the solution ?

Thank you

Hi, @Seb777

Our team is trying to reproduce the issue. I think we are missing something. Could you share your code? Also, you can check your steps according to this documentation:
https://backendless.com/docs/rest/data_transactions_setting_a_relation.html

Hi @Yurii_Zaripa

Here is the json POST to https://eu-api.backendless.com/.../transaction/unit-of-work:

{
   "isolationLevelEnum":"REPEATABLE_READ",
   "operations":[
      {
         "operationType":"UPSERT",
         "table":"Scenario",
         "payload":{
            "name":"Test"
         },
         "opResultId":"scenario-operation"
      },
      {
         "operationType":"UPSERT",
         "table":"Story",
         "payload":{
            "name":"MyStory"
         },
         "opResultId":"story-operation"
      },
      {
         "operationType":"SET_RELATION",
         "table":"Scenario",
         "payload":{
            "parentObject":{
               "___ref":true,
               "opResultId":"scenario-operation"
            },
            "relationColumn":"storyId",
            "unconditional":[
               {
                  "___ref":true,
                  "opResultId":"story-operation"
               }
            ]
         },
         "opResultId":"relation-story-operation"
      }
   ]
}

Hi @Seb777 ,

Sorry for delay with response.
You receive this error because objects IDs for parent and child is not properly referenced in “set relation” command. Your references to the previous operations of transaction are not complete and missing “propName” field.

Valid payload for request should look in this way:

{
   "isolationLevelEnum":"REPEATABLE_READ",
   "operations":[
      {
         "operationType":"UPSERT",
         "table":"Scenario",
         "payload":{
            "name":"Test"
         },
         "opResultId":"scenario-operation"
      },
      {
         "operationType":"UPSERT",
         "table":"Story",
         "payload":{
            "name":"MyStory"
         },
         "opResultId":"story-operation"
      },
      {
         "operationType":"SET_RELATION",
         "table":"Scenario",
         "payload":{
            "parentObject":{
               "___ref":true,
               "opResultId":"scenario-operation",
               "propName": "objectId"
            },
            "relationColumn":"storyId",
            "unconditional":[
               {
                  "___ref":true,
                  "opResultId":"story-operation",
                  "propName": "objectId"
               }
            ]
         },
         "opResultId":"relation-story-operation"
      }
   ]
}

Could you please try suggested payload and write me back about result?

Regards, Andriy

Hi @Andriy_Konoz

Thank you for your help, it works now !

Regards,

Seb