1

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?

1
  • You can test it - do they appear in the web interface? Which documentation are you referring to? Commented Nov 15, 2015 at 9:40

1 Answer 1

3
  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.

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

Comments

Your Answer

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