including(required:)
Returns a request that fetches the record associated with each record in this request. Records that do not have an associated record are discarded.
func including<A>(required 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(required: Book.author)
.asRequest(of: BookInfo.self)
.fetchAll(db)