1

I have Messages class table and inside the table contains "messageTextColumn" column and "user" column.

This "user" column, I created it with type pointer and the target class is _User which is parse main class.

I want to store both user's saved messages and the userId so that I can query it and show it in that user's message tableview cell which will show the list of every messages that the user had saved in my app.

This is my code:

 @IBAction func addMessage(sender: AnyObject) {
    var newMessage = addMessageText.text

    let message = PFObject(className: "Messages")
    var user = PFUser.currentUser()
    message["messageTextColumn"] = newMessage
    message["user"] = user

    message.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
        if (success) {
            println("added to Message Class")
           println(user)
            message.saveInBackground()
        } else {
            // Error saving message
        }
    }
}

The problem is when I run this, the log shows:

[Error]: can't add a non-pointer to a relation (Code: 111, Version: 1.7.4)

and the message was not saved on Parse at all but when I deleted this line of code:

message["user"] = user

I was able to save the message to Parse Messages class table but not the userID of the user who saved it.

2 Answers 2

1

In your code you're trying to add an entire user object when you say you only want to add the user's object ID. If you only want to add the user's object ID then you would do the following:

// ...
message["user"] = PFUser.currentUser().objectId

And in your database your user column would be of String type.

If you actually wanted to add the entire user object as a relation to your message object then you would add the user like you did:

// ...
message["user"] = PFUser.currentUser()

And in your database your user column would be of Pointer type to _User.

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

Comments

0

I figured it out! This is a Swift language issue. Write the query in Obj-C and it should work perfectly!

1 Comment

Fleshing out the answer with a sample code snippet would have gone a long way towards making this a good answer.

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.