I can't make a relationship between 2 Tables in Backendless 4.0 via API

Hi Backendless Team,I’ve declared 2 tables with a one-to-many Relationship but at the moment to add this relation , it never appears in console

Users Table–>1:n–>Risk Table

I’m using “addRelation()” property because I will add more objectds itne the future, and it does not contain a whereClause

This is my code:

Backendless.Data.of(Users.class).findById(currentUser.getObjectId(),new AsyncCallback<Users>()
{
@Override
public void handleResponse(Users response)
{
user=response;
user.getRiesgo().add(resul);
Backendless.Data.of(Users.class).addRelation(user, “risk”, user.getRiesgo(), new AsyncCallback<Void>()
{
@Override
public void handleResponse(Void response)
{
showToast(“USER-RISK SAVED”);
}

        @Override
        public void handleFault(BackendlessFault fault)
        {
            showToast("USER-RISK FAILED" + fault.getMessage());            }        });

}

@Override
public void handleFault(BackendlessFault fault) {
    showToast("NO SE ENCONTRO AL USER- " + fault.getCode());
}

});

Please Help.
Thanks a lot

What is the name of the column in the Users table?

Hi Mark, the name is risk

What is your application ID?

Hi Mark, the name is risk
I attache a screenshoot

image.jpg

Thanks, but I need your application ID to diagnose the problem.

In my code I forgot to say that “resul” is a object of ResultadoCuestionario Table

Backendless.Data.of(Users.class).findById(currentUser.getObjectId(), new AsyncCallback<Users>()
{
@Override
public void handleResponse(Users response)
{
user=response;
user.getRisk().add(resul);
Backendless.Data.of(Users.class).addRelation(user, “riesgo:ResultadoCuestionario:n”, user.getRiesgo(), new AsyncCallback<Void>()
{
@Override
public void handleResponse(Void response)
{
showToast(“USER-RIESGO SAVED”);
}

        @Override
        public void handleFault(BackendlessFault fault)
        {
            showToast("USER-RIESGO FAILED");
        }
    });

}

@Override
public void handleFault(BackendlessFault fault) {
    showToast("NO SE ENCONTRO AL USER- " + fault.getCode());
}

});

this is my application Id:

826EA4B9-7AE7-A82C-FF38-F196AF347B00

Ok, problem number 1:

You defined your own Users class. That is wrong and will lead to a bunch of problems.

Do not use Users.class, instead, change the code to use BackendlessUser.class.

Please make the change and let us know if the problem still exists.

Regards,
Mark

Thanks for the response, I will make this change to see what happen.
Regards

this is my application Id:

826EA4B9-7AE7-A82C-FF38-F196AF347B00

Hi Mark, I could make the relationship with the changes you told me ,but I got this exception inside of Backendless.Data.of(BackendlessUser.class).addRelation…

FATAL EXCEPTION: main java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Void

Backendless.Data.of(ResultadoCuestionario.class).save(resul, new AsyncCallback<ResultadoCuestionario>()
{
@Override
public void handleResponse(final ResultadoCuestionario response1)
{
showToast(“SUCCESSFULL TABLA RIESGO:” +" " + response1.getObjectId());
ArrayList<ResultadoCuestionario> lista=new ArrayList<ResultadoCuestionario>();
lista.add(resul);

    Backendless.Data.of(BackendlessUser.class).addRelation(currentUser, "risk",lista, new AsyncCallback&lt;Void&gt;()
    {
        @Override
        public void handleResponse(Void response)
        {
            showToast("SUCCESSFULL USER-RIESGO");
        }

        @Override
        public void handleFault(BackendlessFault fault)
        {
            showToast("UNSUCCESSFULL USER-RIESGO");
        }
    });

}

@Override
public void handleFault(BackendlessFault fault)
{
    showToast("FAILED TO SAVE RESUL CUIESTIONARIPO:" +" " + fault.getCode());
}

});

according to documentation I had to use Void<Integer> but when I use it all the code lighights in red

“Void<integer>” does not make sense. Where do you see it in the docs?

Sorry for the mistake, I made a mistake reading the docs, but in the docs there is this example:

Person personObject = // personObject retrieval is out of scope in this example
Address addressObject = // addressObject retrieval is out of scope in this example

ArrayList<Address> addressCollection = new ArrayList<Address>();
addressCollection.add( addressObject );

Backendless.Data.of( Person.class ).addRelation( personObject, “address:Address:n”, addressCollection,
new AsyncCallback<Integer>()
{
@Override
public void handleResponse( Integer response )
{
Log.i( “MYAPP”, “related objects have been added”);
}

@Override
public void handleFault( BackendlessFault fault )
{
Log.e( “MYAPP”, "server reported an error - " + fault.getMessage() );
}
} );

and I do he same in my code but everythings highlights in red

ArrayList<ResultadoCuestionario> lista=new ArrayList<ResultadoCuestionario>();
lista.add(resul);

Backendless.Data.of(BackendlessUser.class).addRelation(currentUser, “riesgo”, lista, new AsyncCallback<Integer>()
{
@Override
public void handleResponse(Integer response) {

}

@Override
public void handleFault(BackendlessFault fault) {

}
});

I attached a screnshoot

Hi Nathan,

What does the error message in the popup (when you place the cursor on a red line) says? Also, which version of Backendless Android SDK do you use?

Hi Sergey,
I’ve realised that the 3rd parameter must be a String in order to fix the error, but according to documentation it may be a String clause or ArrayList<> ,but with the last one does not work , the popup only says cannot resolve method addRelation… anonymous com.backendless.async.AsyncCallBack<java.lang.Integer>
and I’m using gradle

I attached other screenshoot

check the backendless version
if you use gradle write in dependencies:

compile 'com.backendless:backendless:4.0.0-beta1'

There is actually beta 2 now:
https://search.maven.org/#artifactdetails|com.backendless|backendless|4.0.0-beta2|jar