user4387360
user4387360

Reputation:

Parse: change a pointer's value

For example, I have two class Player and Game, and Game has a field player which is a pointer to Player. As Parse documentation says, save is recursive, so I assume that I can save a player by only saving a game, just like:

let player = PFObject(className: "Player")
player["name"] = ABC
let game = PFObject(className: "Game")
game["player"] = player
game["round"] = 1
game.saveInBackground()

Is this true?

Ok, now assuming that is true, then what about changing the player's name by only saving game? Like:

let player = game["player"] as! PFObject
player["name"] = BCD
game["round"] = 2
game.saveInBackground()

Could you please answer these two questions? Thank you.

Another question: If I want to get the player["name"], do I need to use includeKey("player") when querying the game?

Upvotes: 1

Views: 115

Answers (1)

Daniel Zhang
Daniel Zhang

Reputation: 5858

  1. Yes, it's true about the recursive saving when you save an object that includes pointers to other objects. All of the pointed-to objects will be saved. Since game points to player, player will also be saved when game is saved.

  2. The changes in a related object, such as the player's name, should also be saved based on (1).

  3. Since queries do not automatically retrieve related objects in a corresponding recursive manner, you are correct about needing to use includeKey to retrieve the related Player object when retrieving a Game.

Upvotes: 3

Related Questions