Start a new topic

How to access the referenced fields?

i have two collections

public class Question extends GenericJson



String qid;


String question;


public class Response extends LinkedGenericJson



String uid;


KinveyReference questionId;


String answer;


i am successfully saved and fetched

I want to access the the 'Question' collection fields from the Response class object when it is fetched from the database..

1 person has this question

If both entities are successfully saved, and the reference has been created, than you can resolve it using appdata.

Try something like this (I am assuming the `Response` collection is called Responses):

Query q = new Query();

myClient.appData("Responses", Response.class).get(q, new String["questionId"], new KinveyListCallback(){ ... });

Note there are overloaded variations of the `appdata.get` and `appdata.getEntity` methods, which all take a String[] as a second argument. Use that String array to pass the field names of the KinveyReferences you want to resolve, in this case it is `questionId`.

Now, within the callback, you will have an array of `Response` objects. One each one you can call either `getTypedObject(Question.class)`, or just `getResolvedObject()` to get the GenericJson class for the Question object. Take a look at the KinveyReference documentation, it might help explain this:

Let me know if that works, and if you have any more questions.
i retrived it using

Query q = new Query();


Splash.mKinveyClient.appData("EmployeeResponse", UserResponseStructure.class).get(q, new String[]{"questionId"},new KinveyListCallback(){

and used

QuestionStructure Q=questionId.getTypedObject(QuestionStructure.class);

to get Question object but i am getting, Error as :

05-19 11:59:07.641: I/error name(1088): java.lang.Object cannot be cast to

Thanks...Edward i found the answer.

i was referencing different field other than _id of question....

ok, i am having trouble fetching the object. Let's say I have two collections, CollectionA and CollectionB, CollectionA has a kinvet reference to CollectionB. Data is successfully stored on the database, and when I retrieve it, I get the correct _id associated with CollectionA and the reference in CollectionB like so:

But... when I try to do CollectionA.getMyObject().getResolvedObject, it will return null

Note that this is an ArrayList<KinveyReference> 

Can anyone shed light on this?



You should be able to do this simply by invoking appdata.get as outlined in the relationalData - Fetching part of the java guide.


Login or Signup to post a comment