Reputation: 1244
In the Parse SDK relation section, it gives the following code:
// Create the post
ParseObject myPost = new ParseObject("Post");
myPost.put("title", "I'm Hungry");
myPost.put("content", "Where should we go for lunch?");
// Create the comment
ParseObject myComment = new ParseObject("Comment");
myComment.put("content", "Let's do Sushirrito.");
// Add a relation between the Post and Comment
myComment.put("parent", myPost);
// This will save both myPost and myComment
myComment.saveInBackground();
This is great, and it works. If you pin the "MyComment" to the local datastore, it looks like it even saves the "MyPost" object as well. There appears to be an issue though, and that is that the Parent Object (the Post) does not get pinned.
I have the following code:
ParseQuery<ParseObject> bjjHistoryCheck = ParseQuery.getQuery("bjjMatchMoves");
// bjjHistoryCheck.fromPin("bjjMatches");
// bjjHistoryCheck.whereEqualTo("className", "bjjMatches");
bjjHistoryCheck.fromLocalDatastore();
// bjjHistoryCheck.whereEqualTo("matchLoser", "Debbie Sanchez");
bjjHistoryCheck.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
Log.i("parse Exception", e.getMessage());<---------
long e1 = new DateTime().getMillis();
Log.i("time to find user matches: ",
String.valueOf(e1 - s1) + " ms + count: " + String.valueOf(count));
if (count < 1) {
noHistoryDialog();
} else {
final Intent intent = new Intent(getActivity(), Dialog_History.class);
intent.putExtra("classToShow", 1);
startActivity(intent);
}
This works as intended, because I pinned the "bjjMatchMoves", just like I would the comment, and I get back a count of how many moves are in the local data store. If I replace the moves query, with one for the matches (the posts) then it fails to find anything. You can see a number of commented out lines...I tried searching every way I could think...nothing. If I remove the localdatastore option, then it successfully finds the records in the cloud.
The line with the arrow shows the following in LogCat:
07-15 22:58:26.018: I/parse Exception(24145): Attempted to fetch an object offline which was never saved to the offline cache.
So I ask you all...How would you pin both the Comment AND the Post? Is it possible? The only way I can think of doing this now, is a dirty way: Create the Match object when the Activity firs starts, then immediately save it in background. Once saved, re-retrieve it, then update it with any information entered, plus point any moves recorded towards it, but it would be much cleaner if there was a way to specify the match and moves are pinned.
Upvotes: 1
Views: 2769
Reputation: 1244
This ended up being a problem with the datastore, for some reason there were some empty objects in the datastore. Once I reset the datastore (cleared app data), the pinning worked as expected. I do not yet know how the empty objects were created (had no data whatsoever, not even a objectId).
Upvotes: 3