mapFromCompanion method
Converts a companion
to the real model class, D
.
Values that are Value.absent in the companion will be set to null
.
Implementation
D mapFromCompanion(Insertable<D> companion) {
final asColumnMap = companion.toColumns(false);
if (asColumnMap.values.any((e) => e is! Variable)) {
throw ArgumentError('The companion $companion cannot be transformed '
'into a dataclass as it contains expressions that need to be '
'evaluated by a database engine.');
}
final context = GenerationContext(SqlTypeSystem.defaultInstance, null);
final rawValues = asColumnMap
.cast<String, Variable>()
.map((key, value) => MapEntry(key, value.mapToSimpleValue(context)));
return map(rawValues);
}