PrefetchedRowsView

public struct PrefetchedRowsView : Equatable

A view on the prefetched associated rows.

For example:

let request = Author.including(all: Author.books)
let row = try Row.fetchOne(db, request)!

print(row)
// Prints [id:1 name:"Herman Melville"]

let bookRows = row.prefetchedRows["books"]
print(bookRows[0])
// Prints [id:42 title:"Moby-Dick"]
  • True if there is no prefetched associated rows.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • The keys for available prefetched rows

    For example:

    let request = Author.including(all: Author.books)
    let row = try Row.fetchOne(db, request)!
    
    print(row.prefetchedRows.keys)
    // Prints ["books"]
    

    Declaration

    Swift

    public var keys: Set<String> { get }
  • Returns the prefetched rows associated with the given key.

    For example:

    let request = Author.including(all: Author.books)
    let row = try Row.fetchOne(db, request)!
    
    print(row)
    // Prints [id:1 name:"Herman Melville"]
    
    let bookRows = row.prefetchedRows["books"]
    print(bookRows[0])
    // Prints [id:42 title:"Moby-Dick"]
    

    Prefetched rows stored in nested “to-one” associations are available, too.

    Nil is returned if the key is not available.

    Declaration

    Swift

    public subscript(key: String) -> [Row]? { get }