Set relation for multiple objects to one object

I have two tables:
Person
Rate: personId(1,1 relation to person)

and I do have many Rate objects related to one person, and I need to update the relation of all rates of a person to another one.
so my case will be:
get all rates where personId=firstPerson.objectId
and update relation personId of all rates to secondPerson.objectId

Hi @adel_kasno

Do you need a help with code?
If so, what platform do you use?

@Maksym_Khobotin yes, I’m using javascript in business logic;

You can achieve this with one API call using bulk update operation:

Your code should look like this:

Backendless.Data.of( "Rate" ).bulkUpdate( " personId = 'FIRST-PERSON-ID' ", { 
  "personId":"SECOND-PERSON-ID" } )

Best Regards,
Maksym

Error: Unknown column 'udt.Rate.personId ’ in ‘field list’ (1054)
code:

await Backendless.Data.of( "Rate" ).bulkUpdate( "personId ='" +  oldPerson.objectId + "'", { 
"personId ":"5F2A48AA-222E-43BB-9900-ED0BA6518596" } )

I’ve tried several things but I didn’t come up with a solution, additional help, please.

Does the personId column exist in Rate table?

Yes and if you want to check it:
check line 409 in class UserBusiness
Note: personId is rater in my case, but I’ve said personId just to clarify my problem.
AppId: “5FB0EA72-A363-4451-FFA5-A56F031D6600”

I am looking at your schema. What is the actual name of the column you’re updating? Also, what are the exact values you use in the API call?

@mark-piller Hey , sorry for the late response

 await Backendless.Data.of("rate").bulkUpdate("rater=' " + oldPerson.objectId + " ' ", {
            "rater": "5F2A48AA-222E-43BB-9900-ED0BA6518596"
        });

column that I want to update is rater in table rate, I want to set relation to person with object id :
“5F2A48AA-222E-43BB-9900-ED0BA6518596” in person table

Hello @adel_kasno

I see two problems:

  1. As I see rater.objectId column has String data type. The name looks incorrect and I have created ticket to prohibit dots in the column name BKNDLSS-22984. I have renamed rater.objectId to raterObjectId.
  2. You can not tie object in the following way
await Backendless.Data.of("rate").bulkUpdate("rater=' " + oldPerson.objectId + " ' ", {
            "rater": "5F2A48AA-222E-43BB-9900-ED0BA6518596"
        });

bulk update can update only simple types like String, Number etc. To tie object you should use relation API https://backendless.com/docs/js/data_set_relation_with_condition.html So in your case code should be like the following:
At first you find all objects in table rate that you would like to update https://backendless.com/docs/js/data_search_with_where_clause.html:

var whereClause = "rater=' " + oldPerson.objectId + " ' ";
var queryBuilder = Backendless.DataQueryBuilder.create().setWhereClause( whereClause );

Backendless.Data.of( "rate" ).find( queryBuilder )

then for each found object call

await Backendless.Data.of("rate").setRelation( 
    parentObject,
    "rater",
    "objectId=' 5F2A48AA-222E-43BB-9900-ED0BA6518596 ' ")