简体   繁体   中英

Query a ParseObject(Pointer) in User Class

Hello i am having some trouble in a Query. I made a pointer called "Empresa" in the _User class. i understand that this pointer is a ParseObject.So i did this i tried to do it in two ways...

private void queryEmpresa(){
    ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId);
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            for (ParseObject obj:objects
                 ) {

                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();

            }

        }
    });
}

and also...

 private void queryEmpresa(){
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseUser>() {
        @Override
        public void done(List<ParseUser> objects, ParseException e) {
            for (ParseUser obj:objects
                 ) {
                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();
            }

        }
    });


}

tell me which is the correct code and what do i need to modify in order to work. Can you please explain to me why is the reason this isnt working so that i dont incur into this problem in the near future?.

Try this and check if you get some error from the server:

ParseQuery<ParseUser> query = ParseUser.getQuery();
query.include("Empresa");
query.getInBackground(ParseUser.getCurrentUser().getObjectId(), new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your user and you should be able to retrieve Empresa like this
      empresa = object.getParseObject("Empresa");
    } else {
      // something went wrong. It would be good to log.
    }
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM