Start a new topic

a ArrayList of a embedded class witch has a reference to a other class.

I have a ArrayList of a embedded class witch has a reference to a other class.

I'm using the following method, but the result do NOT contain the reverend class (Elementos) only a KinveyReference to it.



What I have to do to get each object in the ArrayList elementos using one appData.get ???



Thanks,





Query q = getClient().query();

getClient().appData("Condicoes", Condicoes.class).get(q,new String[]{"elementos"},new KinveyListCallback() {







public class Condicoes extends GenericJson{





@Key("_id")

private String id;



@Key("condicoes")

private ArrayList condicoes;



public static class Condicao extends GenericJson{

@Key

private String condicaoId;

@Key

private String nome;

@Key("elementos")

private ArrayList elementos;

@Key("_kmd")

private KinveyMetaData meta;

@Key("_acl")

private KinveyMetaData.AccessControlList acl; //Kinvey access control, OPTIONAL

. . .

}

. . .

}

Edward,

Since a posted this question I changed my code and now I don't have the same class structure. BUT I still have a problem with the getTypedObject. I posted other question https://support.kinvey.com/discussion/201272034/gettypedobject-doesn-t-work#latest.

If you could answer this other question would help a lot.

Thanks
Hey,



sorry for the delay in getting back to you--



This looks like an issue with the async library, as it is missing some of the necessary wrappers for accomplishing this. I have opened a ticket and will get a new release out providing these methods.



You need to use the `resolve_depth` flag for resolving kinvey references. It defaults to 1, however you want a value of 2. This field can be used to resolve "embedded" entity's references, up to an arbitrary depth. In your case, you have `Condicoes` which contains `Condicao`. To resolve in the child `Condicao`, that resolve_depth has to equal 2. Does that make sense?



In the meantime, you can use the synchronous blocking API and just wrap the method call in an async task-- for what it's worth, this is what the library does anyways.







private class getWithReferences extends AsyncTask{

@Override

protected Condicoes[] doInBackground(Void... params) {

Query q = new Query();

Condicoes[] ret = null;

try{

ret = getClient().appData("Condicoes", Condicoes.class).getBlocking(q, new String[]{"elementos"}, 2, true).execute();

}catch (Exception e){

Log.e("Condicoes", e.getMessage());

e.printStackTrace();

}

return ret;

}



@Override

protected void onPostExecute(Condicoes[] condicoes){

if (condicoes == null){

//an exception has occured during execution

}

//else it's good to go, so call the method to update your views here.



}



}





And then, finally, to execute it, call:



new getWithReferences().execute();







Login or Signup to post a comment