Getting pointer data from Parse.com in Android

I am trying to retrieve data from a pointer in my parse.com database from the User class, which is "CompanyId" Pointer Company (it gets the companyId object from the class company) to add this data to another table called "Note" in the "companyId" field when creating an object.

This is my parse.com database:

Class name: User
objectId String | companyId Pointer Company | username String | password String

Class name: Note. objectId String | companyId String | text String

I'm looking for solutions and I don't find anyone as I don't know how to get the value of companyId as it is a pointer.

Thanks in advance for any information.

EDIT: Problem solved, below shows how it worked for me and another way to solve it with "bigdee94".

Thank!

+3


source to share


2 answers


One assistant helped me and this is how we solved it:

Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
ParseObject userObj= user.getParseObject("companyId");
note.put("companyId", userObj.getObjectId().toString());

      

I have founded a curious trick, as if you tried like:



Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
user.getParseUser("companyId");

      

It will not give data in the field, I believe you are accessing the memory where the data is.

Thanks for your time, I hope this helps more people!

+2


source


Carlos, you can try this:
According to the docs, you can use the include () method to call relational data from pointer columns.

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 column objectId

in your table Company

(class) and
objects

is the requested list of
PS objects : you can make a ParseObject companyIdObject

global variable so you can access it from anywhere.

+4


source







All Articles