loadAvg method

Future<OrmMigrationRecord> loadAvg(
  1. String relation,
  2. String column, {
  3. String? alias,
  4. PredicateCallback<OrmEntity>? constraint,
})
inherited

Lazily loads the average of a column in a relation.

Stores the average result as an attribute with the suffix _avg_{column}.

Example:

await post.loadAvg('comments', 'rating');
final avgRating = post.getAttribute<num>('comments_avg_rating') ?? 0;

Implementation

Future<TModel> loadAvg(
  String relation,
  String column, {
  String? alias,
  PredicateCallback<OrmEntity>? constraint,
}) async {
  return _loadAggregate(
    RelationAggregateType.avg,
    relation,
    column,
    alias: alias,
    constraint: constraint,
  );
}