fetchRelated<R extends DatumEntityInterface> method
Future<List<R> >
fetchRelated<R extends DatumEntityInterface>(
- T parent,
- String relationName, {
- DataSource source = DataSource.local,
Fetches related entities for a given parent entity (the internals behind
the deprecated DatumManager.fetchRelated).
Implementation
Future<List<R>> fetchRelated<R extends DatumEntityInterface>(
T parent,
String relationName, {
DataSource source = DataSource.local,
}) async {
if (parent is RelationalDatumEntity) {
final relation = parent.relations[relationName];
if (relation == null) {
throw ArgumentError(
'Relation "$relationName" is not defined on entity type ${parent.runtimeType}.',
);
}
} else {
throw ArgumentError(
'The parent entity must be a RelationalDatumEntity to fetch relations.',
);
}
final relatedManager = Datum.manager<R>();
switch (source) {
case DataSource.local:
return manager.localAdapter.fetchRelated(
parent,
relationName,
relatedManager.localAdapter,
);
case DataSource.remote:
return manager.remoteAdapter.fetchRelated(
parent,
relationName,
relatedManager.remoteAdapter,
);
}
}