0

I am using Parse SDK in Swift and trying to create a new vote Object, then save a pointer to the current user.

I get the following error - [Error]: can't add a non-pointer to a relation (Code: 111, Version: 1.7.1).

func createVoteObject(row: Int, quest: PFObject) {
    var vote = PFObject(className: "Votes")
    vote["user"] = PFUser.currentUser()

    vote.saveInBackgroundWithBlock {
        (success: Bool, error: NSError?) -> Void in
        if error != nil {
            println("Error saving vote object: \(error!)")
        } else {
            Do something else
        }
    }
}

I have no problem adding other properties.

I get the same issue with this function

func saveVoteToUserObject(vote: PFObject, quest: PFObject) {

    if let currentUser = PFUser.currentUser() {
        var userToVoteRelation = currentUser.relationForKey("votes")
        userToVoteRelation.addObject(vote)
        var userToQuestRelation = currentUser.relationForKey("votedOnQuests")
        userToQuestRelation.addObject(quest)

        currentUser.saveInBackgroundWithBlock {
            (success: Bool, error: NSError?) -> Void in
            if error != nil {
                println(error)
            } else {
                println("Successfully saved vote to User object")
            }
        }
    }
}

Any thoughts?

1
  • Did you refresh the user (or fetch is perhaps the current API method). And is user a pointer instead of a relation? Do both sets of code give exactly the same error? Commented Apr 20, 2015 at 19:05

2 Answers 2

1

Wain inspired the fix for this. Had to refresh the user by clearing the cache and logging back in (either using PFUser.logOut() or Reset Contents and Settings in iOS Simulator).

Any time you're trying to create a pointer, need to use the most recent version of the pointer object. I had added some fields to the User object, which weren't being updated in the my PFUser.currentUser() instance, since it is cached.

Sign up to request clarification or add additional context in comments.

Comments

0

Confirmed. I was seeing this error using

newProfileImage["owner"] = PFUser.currentUser()

to set a pointer to the user. The following works:

PFUser.currentUser()?.fetch()

newProfileImage.setObject(PFUser.currentUser()!, forKey: "owner")

Comments

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.