1

This is my first attempt at Core Data and I have the following model:

enter image description here

In short, my Team model has a relationship of players and also games. My player has a relationship of which team they belong to.

When I get to the Game model I have a relationship called playedList that has all the players who played in that game. As there is a chance that a player although in that team hasn't played in that team's game (injured for instance).

I read this about inverse relationships. Does every Core Data Relationship have to have an Inverse?

but I wasn't sure how I'd model this inverse relationship or how vital it would be?

Community
  • 1
  • 1
Jonnny
  • 4,284
  • 10
  • 55
  • 85

1 Answers1

1

You should model the inverse, from Player to Game, as a to-many relationship. It represents all the games played by a given player, so you might call it gamesPlayed.

There are very few situations where you are better off not modelling the inverse, and you should assume that all inverses are vital. In your particular example, I think (going from memory) CoreData will, if you don't specify an inverse, assume that each player can play in only one game. So, when you add a player to a game, they are mysteriously removed from the game they were previously related to.

pbasdf
  • 20,407
  • 3
  • 36
  • 65