getRelationOrLoad<R> method

Future<R> getRelationOrLoad<R>(
  1. String name
)

Get relation or load it if not loaded

Implementation

Future<R> getRelationOrLoad<R>(String name) async {
  if (hasRelation(name)) {
    final relation = getRelation<R>(name);
    if (relation != null) return relation;
  }

  await load(name);
  final relation = getRelation<R>(name);
  if (relation == null) {
    throw Exception('Failed to load relation $name');
  }
  return relation;
}