Skip to content

fromLocalDatastore doesn't work for Relations #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
evgen-povt opened this issue Nov 9, 2015 · 6 comments
Open

fromLocalDatastore doesn't work for Relations #241

evgen-povt opened this issue Nov 9, 2015 · 6 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@evgen-povt
Copy link

There was the same bug in iOS SDK - https://developers.facebook.com/bugs/938451159512610/

ParseQuery<ParseObject> queryState = ParseQuery.getQuery("State");
queryState.fromLocalDatastore();

try {
    ParseObject stateObject = queryState.get(stateId);
    List<ParseObject> parseObjectList = stateObject.getRelation("tests").getQuery().fromLocalDatastore().find();

    // parseObjectList is empty here. Although the data were fetched and pinned earlier.
    // it works perfect if remove fromLocalDatastore() in previous line
} catch (ParseException e) {
    Loggi.e(TAG, "ParseException: " + e);
}
@wangmengyan95 wangmengyan95 added needs more info type:question Support or code-level question and removed needs more info labels Nov 10, 2015
@wangmengyan95
Copy link
Contributor

Hi @evgen-povt, in order to use stateObject.getRelation("tests").getQuery().fromLocalDatastore(), when you pin a State class, you have to fetch the objects under tests relation and pin them explicitly.
For example:

ParseQuery<ParseObject> query = ParseQuery.getQuery("State");
List<ParseObject> objects = query.find();
for (ParseObject object : objects) {
  // Pin all children explicitly
  ParseObject.pinAll(object.getRelation("tests").getQuery().find());
  object.pin();
}

It is a little bit inconvenience and we will definitely improve it in the future.

@evgen-povt
Copy link
Author

Hi @wangmengyan95,
thank you for the answer. It works!

I believe the issue shouldn't be marked as a question, but the bug, because the iOS SDK works as expected, and doesn't require to pin every relation explicitly.

@wangmengyan95 wangmengyan95 added type:bug Impaired feature or lacking behavior that is likely assumed and removed type:question Support or code-level question labels Nov 11, 2015
@wangmengyan95
Copy link
Contributor

@evgen-povt thanks for the information.

@wangmengyan95 wangmengyan95 self-assigned this Nov 11, 2015
@Toofoo
Copy link

Toofoo commented Aug 12, 2016

For a query from a ParseRelation , even if I call ParseObject.pinAllInBackground( ) when the Object is retrieved from the remote DB, I cannot find it in the LocalDataStore on a next call.
Are you sure that the pinAllInBackground() method works correctly for objects found from a ParseRelation?

@Toofoo
Copy link

Toofoo commented Sep 19, 2016

I confirm that the query result is not persisted in cache even like this :
ParseObject.pinAll( myObject.getRelation("testRelation").getQuery().find() );
myObject.pin();

If then I call the same query from the localDatastore it will find the result only if I don't stop the application. If I restart the application the query from localDatastore will return an empty result.

@Allsimon
Copy link
Contributor

Used to have the same issue... Honestly, triple check with a real dataset if the localdatastore is not too slow (it will slow to a crawl REALLY fast, with just as few as 2000 objects in there. See issue #279) and consider using another more tested datastore (for example, Realm is awesome)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants