including(all:)
Returns a request that fetches all records associated with each record in this request.
func including<A>(all association: A) -> Self where A : AssociationToMany, Self.RowDecoder == A.OriginRowDecoder
For example, we can fetch authors along with their books:
struct Author: TableRecord, FetchableRecord, Decodable {
static let books = hasMany(Book.self)
}
struct Book: TableRecord, FetchableRecord, Decodable { }
struct AuthorInfo: FetchableRecord, Decodable {
var author: Author
var books: [Book]
}
let authorInfos = try Author.all()
.including(all: Author.books)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)