Skip to content

Multiple table results in a single request #1737

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

You must be logged in to vote

Hello @Pomanks,

It looks like you want to perform two fetches, one for the space, and another one for the plants, and compose the results in your Value type:

func fetch(_ db: Database, spaceId: Space.ID) throws -> Value? {
    // One fetch...
    guard let space = try Space.fetchOne(db, id: spaceId) else {
        return nil
    }

    // Another fetch...
    let plantInfos = try Plant
        .including(required: Plant.scientificClassification)
        .asRequest(of: PlantInfo.self)
        .fetchAll(db)

    // ...et voilà!
    return Value(space: space, plantInfos: plantInfos)
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Pomanks
Comment options

@groue
Comment options

groue Mar 3, 2025
Maintainer

Answer selected by Pomanks
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