sanitizeIncomingData method

  1. @override
Map<String, dynamic> sanitizeIncomingData({
  1. required Map<String, dynamic> entity,
  2. required List<Column> columns,
})
override

Implementation

@override
Map<String, dynamic> sanitizeIncomingData(
    {required Map<String, dynamic> entity, required List<Column> columns}) {
  Map<String, dynamic> data = new Map();
  columns.forEach((column) {
    if (column.type == ColumnType.BOOLEAN) {
      data[column.name as String] =
          entity[column.attributeName] == true ? 1 : 0;
    } else if (column.relation != null) {
      if (column.relation?.relationType != RelationType.OneToMany) {
        final entityByAttribute = entity[column.attributeName];

        if (entityByAttribute != null) {
          data[column.name as String] =
              entityByAttribute.runtimeType == String
                  ? entityByAttribute
                  : entityByAttribute[column.relation?.referencedColumn];
        }
      }
    } else {
      if (entity[column.attributeName] is List) {
        data[column.name as String] = entity[column.attributeName].toString();
      } else {
        data[column.name as String] = entity[column.attributeName];
      }
    }
  });

  return data;
}