Database Relationship

Hey,

In the Data store I have in the tabel1 a relationship with table2, when I want to assign a value in the tabel1 using javascript, it is not assigned but when I try it without relationship it is done.

So is there something that I have to do to fix it?

Hello @Hassan_Serhan

for establishing relationships use this API https://backendless.com/docs/js/data_set_relation_with_objects.html

Regards, Vlad

I had set the relationship between the tables manually, I have to do that in code as well?

I’m not sure I understand you, could you please be more specific and describe what you want to get at the end

I have a column named From in user (table) in 1to1 relation with location, in the json request sent by Client side there is a From variable has type: Location.

userDetails(user){
var fromLocation = location.save(user.From);
user.From = user.From.id; //here From is not assigned in the data table but it is assigned when it is not in relation with table2
return user.save( user);
}
This what From contains: From { “id”:, “longitude”:,“lagitude”:}

you can not setup relations in this way

user.From = user.From.id;
user.save( user);

see my the first comment in the topic, there is a link to doc how to work with relations

Regards, Vlad

My code shown above is not a setup relations, the relation was set up manually in tables.

Hi Hassan,

manually you have setup relationship in DB schema - this is not the same as relationship between two objects in tables. You now have schema to save objects with relations (user with From in your case), and for establishing relationship between user objects in table1 and table2 you must use relations API, documentation provided in the first post here.

1 Like

So in my case, could you please provide me the sample using this:
Backendless.Data.of( “TABLE-NAME” ).setRelation(
parentObject,
relationColumnName,
childrenArray )

Backendless.Data.of( “TABLE-NAME” ).setRelation(
user,
"From",
[object-id-1, object-id-2, object-id-N] )
1 Like

Thank you!! It works 100%.

Best regards,