1

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!)")
         }

2 Answers 2

2

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)
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

5 Comments

Thanks for the response. So I'm with you about the query needing a different data type. In my example, selectedBook is a string of the book objectID. What should I use instead of this objectID to be able to search for the tags just for this book? Thanks for your assistance!
And what is the datatype of the key "book"? Isn't it an object?
"book" is a column in my userTags class that holds a pointer to the book object. The user selects a specific book in prior view controller. I am then trying to pass this book objectID in to query the user tags for only that selected book. I just am unclear what I need to put in query.whereKey("book", equalTo:selectedBook) to get it to pull the tags for the book. Thank you!!
I think the fact that you're passing an object via "book" is the source of problem. Try passing ID of this object there.
Thanks again for your response. So you're saying to change the column in Parse to be just a string of that book object ID rather than being a pointer to the object itself? Sorry, I'm just trying to get my head wrapped around this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.