Android - Creating user relations steps

Hi There,
I have a list of users in my app which i need to create relations between them, friendships. Following is what i am doing:
BackendlessUser mCurrentUser = getApplicationContext().getUser(); // get current user
List<String> relations = new ArrayList<>(); // create a list of relations
relations.add(“KEY_FRIENDS_RELATION”); //
mCurrentUser.setProperty(“freindsRels”, relation); // set a new property/column name in backend
// and reload the relations so my current user
Backendless.Data.of(BackendlessUser.class).loadRelations(mCurrentUser, relations, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser backendlessUser) {
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
}
});
Now, from dashboard, I am expecting a new column to generated and there is none. Am i missing a step here?
Thank you,
–Armen

Would you please give all steps that is necessary to create a relations between a list of users. I am sure this will be ask again and again. There are online courses that are heavily relaying on parse.com API and lots of other students will end up migrating to Backendless.com API.

Thanks again,

–Armen

Armen,

What should be in the relation? It is not clear from the code. Think of the relations as the “has” property. For example:

“Person” has “Address”
In this case, table Person will have a one to one relation with the Address table. In the code the Person class will have a field/property of type Address.

or
“Person” has “Friends”
In this case table Person will have a one to many relation with the Friend table. In the code the Person class will have a field/property of type List<Friend>.

With that said, what is it you’re looking to get?

Regards,
Mark

Hi Mark,

I have a table called Users, which has two user rows. I am trying to create a relation between these two users. The problem i am trying to solve is to relate two rows dynamically to each. I cannot find the steps in developer docs.

    I know if user A is trying to create a relation with user B in a different table, then he has to have a property named, lets say "friends_relation". So, we create a List of relation and add the freiend_relation as a property of User A. Or, maybe this new property should be added to Table itself? I am not sure of this part. Then, From my App's UI, i will select the current logged in user, as well as the user B which is in the list by clicking on them. This way user A and B will be linked to each other. 

Here is my source code : https://github.com/VZAG/android/blob/master/Rab/app/src/main/java/agharibi/com/rab/EditFriendsActivity.java

Also, i have a screen shot from my table.

Thank you,

–Armen

The code logic for creating a relation and getting the current user is in onResume() of EditFriendsActivity.java. Also, onSelectedItemClick() is called when the user selects a user from user list in the UI.

Creating a relationship between tables using Backendless console:

https://backendless.com/feature-11-declaring-relations-between-tables-classes-using-developer-console/

Creating a relationship between tables/objects without console, just with code:
https://backendless.com/feature-7-creating-data-tables-to-store-objects-in-console/

In your case if you need a relationship between a user object and another object, it could not be simpler. If you want to accomplish it with the code, then just do this (the code uses sync API, if you need to run it in Android, change to async API OR run this code on a non UI thread):

BackendlessUser user1 = Backendless.Data.of( BackendlessUser.class ).findFirst();
BackendlessUser user2 = Backendless.Data.of( BackendlessUser.class ).findLast();


ArrayList&lt;BackendlessUser&gt; friends = new ArrayList&lt;BackendlessUser&gt;();
friends.add( user2 );


user1.setProperty( "myfriends", friends );


Backendless.Data.of( BackendlessUser.class ).save( user1 );

Thank you so much Mark! You guys are Awesome!