Skip to content

Fetching a hierarchy of records #1718

Answered by groue
matiaskorhonen asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @matiaskorhonen,

I imagine it could look something like this, but I'm having issues figuring out the correct request structure for it:

Yes I think that's it. This plain Swift structure does encode the hierarchy you're after, right?

You might be bothered by the collections property name, because it's not really an array of Collection. You can rename it:

struct LibraryInfo: Decodable, FetchableRecord {
    struct CollectionInfo: Decodable {
        var collection: Collection
        var books: [Book]
    }
    var library: Library
    var collectionInfos: [CollectionInfo] // customized name
}
let results: [LibraryInfo] = try Library
    .including(all: Library.collections
        .f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@matiaskorhonen
Comment options

Answer selected by matiaskorhonen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants