transformSerialize method

Map<String, dynamic> transformSerialize(
  1. Map<String, dynamic> map, {
  2. bool withRelationships = true,
})

Implementation

Map<String, dynamic> transformSerialize(Map<String, dynamic> map,
    {bool withRelationships = true}) {
  for (final e in relationshipMetas.entries) {
    final key = e.key;
    if (withRelationships) {
      final ignored = e.value.serialize == false;
      if (ignored) map.remove(key);

      if (map[key] is HasMany) {
        map[key] = (map[key] as HasMany).keys;
      } else if (map[key] is BelongsTo) {
        map[key] = map[key].key;
      }

      if (map[key] == null) map.remove(key);
    } else {
      map.remove(key);
    }
  }
  return map;
}