fieldForKey method
Transforms a key
into a model's field.
This mapping can also be done via json_serializable
's @JsonKey
.
If both are used, fieldForKey
will be applied before
reaching fromJson
.
Implementation
@protected
@visibleForTesting
String fieldForKey(String key) {
if (key.endsWith(identifierSuffix)) {
final keyWithoutId =
key.substring(0, key.length - identifierSuffix.length);
if (_belongsTos.keys.contains(keyWithoutId)) {
return keyWithoutId;
}
}
return key;
}