AssociationAggregate
A value aggregated from a population of associated records.
struct AssociationAggregate<RowDecoder>
You build an AssociationAggregate
from an AssociationToMany
.
For example:
struct Player: TableRecord { }
struct Team: FetchableRecord, TableRecord {
static let players = Team.hasMany(Player.self)
}
try dbQueue.read { db in
// An association aggregate
let playerCount = Team.players.count
// Fetch all teams with at least ten players:
let teams: [Team] = try Team
.having(playerCount >= 10)
.fetchAll(db)
}
Instance Methods
func forKey(String
) -> AssociationAggregate<RowDecoder> Returns an aggregate that is selected in a column with the given name.
func forKey(some CodingKey
) -> AssociationAggregate<RowDecoder> Returns an aggregate that is selected in a column named like the given coding key.
Top-Level Functions
func abs<RowDecoder>(AssociationAggregate<RowDecoder>
) -> AssociationAggregate<RowDecoder> The
ABS
SQL function.func cast<RowDecoder>(AssociationAggregate<RowDecoder>, as: Database.StorageClass
) -> AssociationAggregate<RowDecoder> The
CAST
SQL function.func length<RowDecoder>(AssociationAggregate<RowDecoder>
) -> AssociationAggregate<RowDecoder> The
LENGTH
SQL function.