parseImplicitManyToManyTableName function

ParsedImplicitManyToManyTableName? parseImplicitManyToManyTableName(
  1. String tableName
)

Parses an implicit relation table name produced by this package.

Implementation

ParsedImplicitManyToManyTableName? parseImplicitManyToManyTableName(
  String tableName,
) {
  if (!isImplicitManyToManyTableName(tableName)) {
    return null;
  }

  final encoded = tableName.substring(kImplicitManyToManyTablePrefix.length);
  final segments = encoded.split('__');
  if (segments.length != 4 || segments.any((segment) => segment.isEmpty)) {
    return null;
  }

  return ParsedImplicitManyToManyTableName(
    firstModelName: _decodeIdentifierSegment(segments[0]),
    firstFieldName: _decodeIdentifierSegment(segments[1]),
    secondModelName: _decodeIdentifierSegment(segments[2]),
    secondFieldName: _decodeIdentifierSegment(segments[3]),
  );
}