Instance Methodgrdb 7.3.0GRDB

including(optional:)

Returns a request that fetches the eventual record associated with each record of this request.

RequestProtocols.swift:1194
func including<A>(optional association: A) -> Self where A : Association, Self.RowDecoder == A.OriginRowDecoder

For example, we can fetch books along with their eventual author:

struct Author: TableRecord, FetchableRecord, Decodable { }
struct Book: TableRecord, FetchableRecord, Decodable {
    static let author = belongsTo(Author.self)
}

struct BookInfo: FetchableRecord, Decodable {
    var book: Book
    var author: Author?
}

let bookInfos = try Book.all()
    .including(optional: Book.author)
    .asRequest(of: BookInfo.self)
    .fetchAll(db)