Reputation: 41
I have leagues that have teams that have players. A player can belong to different teams and leagues. A team can belong to different leagues. I am having trouble setting these relationships with Realm.
class League: RLMObject
{
dynamic var name = "name"
dynamic var teams = RLMArray(objectClassName: Team.className())
}
class Team: RLMObject
{
dynamic var name = "name"
var leagues: [League] {
return linkingObjectsOfClass("League", forProperty: "teams") as [League]
}
dynamic var players = RLMArray(objectClassName: Player.className())
}
class Player: RLMObject
{
dynamic var name = "name"
var teams: [Team] {
return linkingObjectsOfClass("Team", forProperty: "players") as [Team]
}
}
Upvotes: 2
Views: 353
Reputation: 41
The relationships are correct, it was the way I was presenting the data on the view that was the problem. So this is an example of the correct way of representing these relationships.
Upvotes: 2