fieldForKey method

  1. @protected
  2. @visibleForTesting
String fieldForKey(
  1. String key
)
inherited

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;
}