I have created three tables in Realm and there are relationships identified between them (LBContests <-> LBQuizzes <-> LBLeaders) and each is many to many relationships. This is to represent leader boards where there are "LBLeaders" for "LBQuizzes" within "LBContests" and the LBLeaders contains userNames (I spared the additional field details where the score is tracked as an example - for simplicity).
import Foundation
import RealmSwift
class LBContests: Object {
@objc dynamic var contestName: String = ""
let childrenLBQuizzes = List<LBQuizzes>()
}
class LBQuizzes: Object {
@objc dynamic var quizName: String = ""
let childrenLBLeaders = List<LBLeaders>()
var parentContest = LinkingObjects(fromType: LBContests.self, property: "childrenLBQuizzes")
}
class LBLeaders: Object {
@objc dynamic var userName: String = ""
var parentQuizzes = LinkingObjects(fromType: LBQuizzes.self, property: "childrenLBLeaders")
}
With knowing the contestName and the quizName, I am trying to identify how to add userNames within LBLeaders related to LBQuizzes (with the known quizName) and further related to LBContests (with the known contestName).
I have tried searching, reading, watching videos - but they are all for simple one or two level relationships and I need to handle 3 levels of relationships. I have only been able to append LBQuizzes to the LBContests.childrenLBQuizzes, but haven't been able to find a way to then append a LBLeaders record to the LBContests record that has a child LBQuizzes record and its childrenLBLeaders record(s)...(for the known contestName and quizName)
I know that part of my problem is that I don't fully understand the differences and when to use Objects versus Results versus Lists... I can perform a filter to get a Result, but I need an object to either reference the child relationships and/or to append a record...
Can someone please:
Identify the Swift Realm code to add LBLeader records (userName) for the known related LBQuizzes and LBContests
Provide an overview of how, when, and why to use Objects, Results, and Lists properly
Provide insights on how the Objects, Results, and Lists can be used together or definitively identify if they cannot be used together (this is my understanding) - you get Results and/or Lists from or Objects being filtered, but they are not convertible from one to the other (i.e. you can't use a Result or a List like an Object)