Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query on ParseObject

I'm trying to get an Object with a Parse query.

This is my code :

ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> results, ParseException e) {
            if (e == null) {
                // Results were successfully found from the local datastore.
            } else {
                showLog(e.toString());
            }
        }
    });

I get this error:

com.parse.ParseException: java.lang.IllegalStateException: ParseObject has no data for 'objectId'. Call fetchIfNeeded() to get the data.

BTW my Conference Class contains Pointers.

like image 406
bryan leduc Avatar asked Nov 19 '15 11:11

bryan leduc


1 Answers

If you're querying directly from Parse, you can do:

ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
...
query.include("name_of_the_column_containing_a_pointer");
query.include("another_pointer_column");
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> results, ParseException e) {
        if (e == null) {
            // You can now access the pointers specified in the include
        } else {
            showLog(e.toString());
        }
    }
});

Otherwise, if you're querying the local datastore:

ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
...
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> results, ParseException e) {
        if (e == null) {
            ParseObject parseObject = results.get(0); // Get the object
            parseObject.fetchIfNeededInBackground(new GetCallback<ParseObject>() {
                public void done(ParseObject result, ParseException e) {
                    if (e == null)
                        // Do something with result
                }
            }
        } else {
            showLog(e.toString());
        }
    }
});
like image 104
myselfmiqdad Avatar answered Oct 14 '22 14:10

myselfmiqdad