Skip to content

How to chain .including to eagerly load a three level hierarchy? #1590

Closed Answered by tahic-himzo
tahic-himzo asked this question in Q&A
Discussion options

You must be logged in to vote

Solved the problem from a different angle by going for a request model of

struct FullProgrammedSet: Decodable, FetchableRecord {
    var programmedSet: ProgrammedSet
    var programmedSession: ProgrammedSession
    var programmedProgression: ProgrammedProgression
    var routine: Routine
}

and this query:

try! appDatabase.reader.read { db in
  try! ProgrammedSet
      .including(required: ProgrammedSet.session
          .including(required: ProgrammedSession.routine)
          .including(required: ProgrammedSession.programmedProgression)
      )
      .asRequest(of: FullProgrammedSet.self)
      .fetchOne(db)
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tahic-himzo
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
1 participant