Relation to User class via pointer: Error code 102

2k Views Asked by At

I have 2 classes: User, Books

In User table I have: objectId, AuthorName

In Books table I have: objectId, BookName, authorIDptr

AuthorIDptr is a Pointer to User class

When I run this query:

var bookQuery = PFQuery(className:"Books")
bookQuery.whereKey("authorIDptr", equalTo: PFUser.currentUser().objectId)
bookQuery.includeKey("authorIDptr")

var userQuery = PFUser.query()
userQuery.whereKey("BookName", matchesKey: "Curious George", inQuery: bookQuery)

userQuery.findObjectsInBackgroundWithBlock {....

I get the following error:

Error: Error Domain=Parse Code=102 "The operation couldn’t be completed. (Parse error 102.)" UserInfo=0x7ff2e26f4660 {error=pointer field authorIDptr needs a pointer value, code=102} { code = 102; error = "pointer field authorIDptr needs a pointer value"; }

The Class is populated with data. When i click on the pointer in the Books class, it loads the appropriate User class record.

Can someone help show me what I am doing wrong.

What I want to happen: I want all AuthorNames of a book to show up in a tableview.

Thanks,

Dennis

1

There are 1 best solutions below

1
On BEST ANSWER

Change this line:

bookQuery.whereKey("authorIDptr", equalTo: PFUser.currentUser().objectId)

into this:

bookQuery.whereKey("authorIDptr", equalTo: PFUser.currentUser())

Pointers in parse are available via object and not objectId. So when you need to query with pointer, you just pass the whole object to the query and the parse will do the rest for you.