- @override
Converts a value from a more complex value into a primitive value according to this instance's definition.
This method takes a Dart representation of a value and converts it to something that can be used elsewhere (e.g. an HTTP body or database query). How this value is computed depends on this instance's definition.
Source
@override
dynamic convertToPrimitiveValue(dynamic value) {
if (value is ManagedSet) {
return value
.map((ManagedObject innerValue) => innerValue.asMap())
.toList();
} else if (value is ManagedObject) {
// If we're only fetching the foreign key, don't do a full asMap
if (relationshipType == ManagedRelationshipType.belongsTo
&& value.backingMap.length == 1
&& value.backingMap.containsKey(destinationEntity.primaryKey)) {
return {destinationEntity.primaryKey: value[destinationEntity.primaryKey]};
}
return value.asMap();
} else if (value == null) {
return null;
}
throw new QueryException(QueryExceptionEvent.requestFailure,
message: "Invalid value '$value' for property '$entity.$name', "
"expected '${MirrorSystem.getName(destinationEntity.instanceType.simpleName)}'");
}