4

I have a Meal object that stores pointers to n created objects "FoodInfo" using the key "MealItems".

When I query for the meal I take advantage of the [query includeKey:@"MealItems"] to fetch the items pointed to while fetching the "Meal".

This works swimmingly if the objects are created while online (ie. all are stored in the cloud db).

However, since I cannot assume access to the cloud at all time for this app I am now trying to enable the local datastore so I've changed my queries to use: [query fromLocalDatastore];

and I've changed all of my objects' save methods to pinInBackgroundWithBlock followed by (assuming success of local save) saveInBackgroundWithBlock followed by (assuming failure) saveEventually.

To test this, I:

  • turned off wifi
  • ran the code to create a meal and then add newly created foods to it. This works with no error codes.
  • ran a report that then queries for the meal just created. This fails with the following:
Error: Error Domain=Parse Code=121 
"include is invalid for non-ParseObjects" UserInfo=0x60800007f400 {
    error=include is invalid for non-ParseObjects, 
    NSLocalizedDescription=include is invalid for non-ParseObjects, 
    code=121
} {
    NSLocalizedDescription = "include is invalid for non-ParseObjects";
    code = 121;
    error = "include is invalid for non-ParseObjects";
}

Is this scenario not supported?

When I re-enable wifi, the meal is successfully added to the online db, but the query failure still happens when I run the query with the includeKey locally.

Am I missing something here? I'm quite surprised to see this failing. It seems like a really basic feature that should work whether local or cloud based.

Gerald
  • 41
  • 2
  • Show the code you're using for the test – Wain Sep 02 '15 at 07:02
  • 1
    The fundamental question shouldn't require showing code. It is clearly possible to create an object A that contains an array of pointers to other objects and pin them all to the local datastore while offline. Does parse support a local datastore query that retrieves A and the objects pointed to in the array via includekey prior to any of the objects being saved over the network? – Gerald Sep 02 '15 at 18:42
  • Wondering if this was addressed on any of the newer versions or if you would mind to share your workaround if any @Gerald. Thanks – Jaime Agudo Dec 28 '16 at 13:26

1 Answers1

0

Parse objects are not created until you save them. Try using saveEventually first before using pinInBackgroundWithBlock.

Santhosh
  • 691
  • 4
  • 12
  • 1
    Calling saveEventually prior to pinning an object (in the absence of a network connection) doesn't change anything. This results in exactly the same error I reported above. I'm guessing the includekey fails because the PFObject has not been assigned an id and said assignment seems not to occur prior to the object being saved via a network connection. If so, this renders the use of includekey to retrieve 1:n relations unusable for the offline scenario in which objects are created, pinned (and saved eventually), then referenced via a query using includekey. – Gerald Sep 02 '15 at 18:28