Egor Vasilev
Egor Vasilev

Reputation: 43

Parse: how to get pinned object without id

Ive got application on android which should work without internet and with parse database when internet is on. Also I faced with problem of getting of pinned ParseObject which not saved in online database before.

So what I do:

ParseObject car = new ParseObject("cat");
cat.put("name","Pussy");
cat.pinInBackground();

So, now I want to get this cat by query with query.getInBackground but, I cant do it because I haven't objectId, which automatically generated only after saving in online database.

Upvotes: 0

Views: 242

Answers (1)

tilo
tilo

Reputation: 14169

You can search for cats (objects) with given properties in the local datastore:

ParseQuery<ParseObject> query = ParseQuery.getQuery("cat");
query.fromLocalDatastore();
query.whereEqualTo("name", "Pussy");
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> catList, ParseException e) {
        if (e == null) {
            Log.d("cat", "Retrieved " + catList.size() + " cats");
        } else {
            Log.d("cat", "Error: " + e.getMessage());
        }
    }
});

However, if name is the only property, you'll likely get a list of objects with more than one entry. Here, you may add other properties (e.g. an owner) to limit the number of possible matches.

Upvotes: 1

Related Questions