Reputation: 378
I'm trying to do a query by selectedBook (this is a string of selectedBook's objectID). However, I'm getting this error: "[Error]: pointer field book needs a pointer value (Code: 102, Version: 1.8.2)." I believe I have to do the query with the actual book object rather than the objectID, how can I go about doing this? Thanks in advance!!
var query = PFQuery(className:"UserTags")
query.whereKey("book", equalTo:selectedBook)
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved \(objects!.count) tags.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
print(object.objectId)
}
}
} else {
// Log details of the failure
print("Error: \(error!)")
}
Upvotes: 1
Views: 329
Reputation: 378
Figured it out. Here is the code in case someone else runs into this:
let pointer = PFObject(withoutDataWithClassName:"Book", objectId: booksObjectID)
var query = PFQuery(className: "UserTags")
query.whereKey("book", equalTo: pointer)
query.includeKey("book")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
for object in objects! {
self.userTags.addObject(object)
}
}
Upvotes: 2
Reputation: 40030
From documentation:
InvalidQuery - 102 - Error code indicating you tried to query with a datatype that doesn't support it, like exact matching an array or object.
The error description tells you a lot. This kind of querying does not support queuing by object (in your case, book). You have to use a datatype that is supported - for example query by book ID or name which are more primitive data types.
Upvotes: 0