resolveEntityIndexColumns method
The columns of the entityIndex fields of the entityHandler's
entity (in the index's order).
Throws an ArgumentError for an unknown, hidden or collection (relationship) field, or an empty index.
Implementation
List<String> resolveEntityIndexColumns(
EntityHandler entityHandler,
EntityIndex entityIndex,
) {
var fields = entityIndex.fields;
if (fields.isEmpty) {
throw ArgumentError(
"Empty `EntityIndex` fields: `${entityHandler.type}`",
);
}
var fieldsTypes = entityHandler.fieldsTypes();
return fields.map((fieldName) {
var fieldType = fieldsTypes[fieldName];
if (fieldType == null) {
throw ArgumentError(
"Unknown `EntityIndex` field `$fieldName` in `${entityHandler.type}`: "
"$entityIndex",
);
}
if (fieldType.isListEntityOrReference) {
throw ArgumentError(
"Can't index a collection (relationship) field: "
"`${entityHandler.type}.$fieldName` ($entityIndex)",
);
}
var annotations = entityHandler
.getFieldEntityAnnotations(null, fieldName)
?.whereType<EntityField>()
.toList();
if (annotations != null && annotations.hasHidden) {
throw ArgumentError(
"Can't index a hidden field: `${entityHandler.type}.$fieldName` "
"($entityIndex)",
);
}
return normalizeColumnName(fieldName);
}).toList();
}