I want to store a pointer to a specific object as an Object Pointer in a PFConfig
, similar to how objects can point to each other in the database. I see there is a way to create an Object
field in the PFConfig
, but when I enter the corresponding objectID
it says "invalid value for Object Type".
How do I store object links in the PFConfig
?

- 1,724
- 2
- 18
- 22
-
Haven't tried this, so I won't make it an answer yet, but try setting the config value to: `{__type:'Pointer', className:'MyClass', objectId:'1234xyz'}` – danh Jun 11 '15 at 21:50
-
It gives me the same "invalid value for Object type" error. – Satre Jun 11 '15 at 22:49
2 Answers
The Object
field type in PFConfig
in looks like it only stores JSON objects (converted to NSDictionary
with the iOS API), not relations to other Parse objects. And it seems to do some sort of validation, so even if you enter {"__type":"Pointer", "className":"MyClass", "objectId":"1234xyz"}
(which is valid JSON), the save fails validation with a __type field is not allowed.
error.
Doesn't look like it can be done with native functionality sorry. You could store your own pointer style object (i.e., just store the object ID, or a {"type": "pointer", "objectId": "ABC123"}
style reference), but you'd be responsible for managing the relationship, and retrieving the downstream object.
You could also try converting the object you want to save to a JSON representation, but if you wanted to use it as a real PFObject
you'd need to reconstruct the object based on the data in the PFConfig
, and it's probably safer just to load a real PFObject
based on a reference if the ability to update that object is important to your config.

- 9,731
- 1
- 31
- 35
-
1Good answer. Its better that it doesn't work, imo. Saving objectIDs in any format is a brittle dependence on something that ought to be considered internal to the object. Better to save something that will parameterize a query that will result in the desired object. This way the desired object can be deleted and re-added without breaking the config. – danh Jun 11 '15 at 23:39
Expanding on my suggestion under @rickerbh's excellent answer, consider saving something that indicates the desired object, rather than pointing to it. This way it can be found in a query, even if the object's objectId changes.
For example, you could add a config parameter named myConfigParam
equal to { "class":"MyClass", "uniqueField":"foo" }
, where one or more uniqueField attributes fully describe the object. Then, the config'd object can be picked up this way, in objective-c...
- (void)fetchConfigObjectWithCompletion:(void (^)(PFObject *, NSError *))completion {
[PFConfig getConfigInBackgroundWithBlock:^(PFConfig *config, NSError *error) {
if (!error) {
NSString *className = config[@"myConfigParam"][@"class"];
NSString *uniqueField = config[@"myConfigParam"][@"uniqueField"];
PFQuery *query = [PFQuery queryWithClassName:className];
[query whereKey:@"uniqueField" equalTo: uniqueField];
[query getFirstObjectInBackgroundWithBlock:completion];
} else {
completion(nil, error);
}
}];
}
Since the config object is rendered as an NSDictionary, you could even iterate its keys, and add equalTo constraints to the query in a loop without knowing on the client what those keys are.

- 62,181
- 10
- 95
- 136
-
How can you iterate its keys? I see PFConfig has an internal object _parametersDictionary when i'm in the debugger, but how can I access that in code? – xaphod Jun 22 '15 at 20:52