我的联赛中有球员有球员。玩家可以属于不同的团队和联盟。一个团队可以属于不同的联赛。我无法与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]
}
}
答案 0 :(得分:2)
关系是正确的,这是我在视图上呈现数据的方式。所以这是表示这些关系的正确方法的一个例子。