serialize method

  1. @override
Future<Map<String, dynamic>> serialize(
  1. T model, {
  2. bool withRelationships = true,
})
inherited

Returns a serialized version of a model of T, as a Map<String, dynamic> ready to be JSON-encoded.

Implementation

@override
Future<Map<String, dynamic>> serialize(T model,
    {bool withRelationships = true}) async {
  final map =
      localAdapter.serialize(model, withRelationships: withRelationships);

  // essentially converts keys to IDs
  for (final key in localAdapter.relationshipMetas.keys) {
    if (map[key] is Iterable) {
      map[key] = (map[key] as Iterable)
          .map((k) => graph.getIdForKey(k.toString()))
          .filterNulls
          .toList();
    } else if (map[key] != null) {
      map[key] = graph.getIdForKey(map[key].toString());
    }
    if (map[key] == null) map.remove(key);
  }
  return map;
}