relation method
Future<PaginatedRecords>
relation(
- String resourceKey,
- Object id,
- RelationDescriptor relation, {
- int page = 1,
- String? search,
- String? sort,
- String? direction,
override
One relation manager's rows for record id — the same envelope list
parses, against the sibling URL RelationController serves. Unlike
list, the child rows' own key comes from relation itself
(relation.recordKey), not from this resource's schema: the related
model is routinely a different one, with a different route key.
Implementation
@override
Future<PaginatedRecords> relation(
String resourceKey,
Object id,
RelationDescriptor relation, {
int page = 1,
String? search,
String? sort,
String? direction,
}) async {
// The same omission rule as [list]: an unknown sort key is a 422 on the
// relation endpoint too, and a blank search would be a search for nothing.
final response = await _transport.get(
'$prefix/$resourceKey/$id/relations/${relation.key}',
query: {
'page': '$page',
if (search != null && search.trim().isNotEmpty) 'search': search,
if (sort != null && sort.trim().isNotEmpty) 'sort': sort,
if (direction != null && direction.trim().isNotEmpty)
'direction': direction,
},
);
final rows = response['data'];
final meta = response['meta'];
return PaginatedRecords(
records: [
if (rows is List)
for (final row in rows)
if (row is Map<String, dynamic>)
ResourceRecord.fromJson(row, relation.recordKey),
],
meta: PageMeta.fromJson(meta is Map<String, dynamic> ? meta : const {}),
);
}