Retrieves pointer data from Parse.com in Android
I’m trying to retrieve data from a pointer in my parse.com database from the User class, which is the “companyId” pointer that the company (which gets the company objectId from the class Company) adds data from another table named Note to the field named companyId when creating the object.
Here is my parse.com database:
Class Name: User
objectId String|companyId Pointer Company|username String |password String
Class name: Note
objectId string | The companyId string |text string
I’ve been looking for a solution but haven’t found any because I don’t know how to retrieve the companyId value because it’s a pointer.
Thank you in advance for any reply.
EDIT: The problem is solved, here are how it worked for me and other ways for “bigdee94” to solve it.
Thanks!
Solution
Carlos, you can try this:-
According to the documentation, in order to call relational data from a pointer column, you can use the include() method.
For example: –
ParseQuery<ParseObject> userQuery = ParseUser.getQuery();
userQuery.include("companyId");
userQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
userObjects retrieved successfully
ParseObject companyIdObject = (ParseObject) objects.get("companyObjectIdColumn");
} else {
Log.d("objects", "Error: " + e.getMessage());
}
});
where companyObjectIdColumn
is the objectId
column in the Company table (class), and
objects is the
list of
objects
to be queried
P.S: You can set ParseObject companyIdObject
as a global variable so that you can access it from anywhere.